🛠️ Disable tooltip when the icon-button is disabled
This commit is contained in:
parent
d7e5097f6f
commit
a772849df8
2 changed files with 14 additions and 2 deletions
|
|
@ -40,7 +40,7 @@ fun CustomIconButton(
|
|||
onClick: () -> Unit
|
||||
) {
|
||||
var isClicked by remember { mutableStateOf(false) }
|
||||
CustomTooltip(text = stringResource(id = contentDescription)) {
|
||||
CustomTooltip(text = stringResource(id = contentDescription), enabled = enabled) {
|
||||
IconButton(
|
||||
enabled = enabled && !isClicked,
|
||||
modifier = Modifier.focusProperties {
|
||||
|
|
|
|||
|
|
@ -12,13 +12,25 @@ import androidx.compose.ui.unit.dp
|
|||
|
||||
/**
|
||||
* Custom Tooltip.
|
||||
* Shows [text] on long press.
|
||||
*
|
||||
* @param text Text to show.
|
||||
* @param padding Space between [content] and tooltip.
|
||||
* @param enabled Whether this tooltip is enabled.
|
||||
* @param content Content.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun CustomTooltip(text: String, padding: Dp = 14.dp, content: @Composable () -> Unit) {
|
||||
fun CustomTooltip(
|
||||
text: String,
|
||||
padding: Dp = 14.dp,
|
||||
enabled: Boolean = true,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
TooltipBox(
|
||||
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(padding),
|
||||
focusable = false,
|
||||
enableUserInput = enabled,
|
||||
tooltip = {
|
||||
PlainTooltip {
|
||||
Text(text = text)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue