🛠️ 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
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
var isClicked by remember { mutableStateOf(false) }
|
var isClicked by remember { mutableStateOf(false) }
|
||||||
CustomTooltip(text = stringResource(id = contentDescription)) {
|
CustomTooltip(text = stringResource(id = contentDescription), enabled = enabled) {
|
||||||
IconButton(
|
IconButton(
|
||||||
enabled = enabled && !isClicked,
|
enabled = enabled && !isClicked,
|
||||||
modifier = Modifier.focusProperties {
|
modifier = Modifier.focusProperties {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,25 @@ import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Tooltip.
|
* 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)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@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(
|
TooltipBox(
|
||||||
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(padding),
|
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(padding),
|
||||||
focusable = false,
|
focusable = false,
|
||||||
|
enableUserInput = enabled,
|
||||||
tooltip = {
|
tooltip = {
|
||||||
PlainTooltip {
|
PlainTooltip {
|
||||||
Text(text = text)
|
Text(text = text)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue