Skip to content

Commit

Permalink
Allow customization of indication and interaction source of MenuButto…
Browse files Browse the repository at this point in the history
…n and MenuItem
  • Loading branch information
alexstyl committed Jul 15, 2024
1 parent 0ef1ab4 commit 354e7fd
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions core/src/commonMain/kotlin/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.foundation.Indication
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down Expand Up @@ -111,10 +112,20 @@ public fun rememberMenuState(expanded: Boolean = false): MenuState {
}

@Composable
public fun MenuScope.MenuButton(modifier: Modifier = Modifier, contents: @Composable () -> Unit) {
Box(modifier.clickable(role = Role.DropdownList) {
menuState.expanded = menuState.expanded.not()
}) {
public fun MenuScope.MenuButton(
modifier: Modifier = Modifier,
mutableInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication = LocalIndication.current,
contents: @Composable () -> Unit
) {
Box(
modifier.clickable(
role = Role.DropdownList,
interactionSource = mutableInteractionSource,
indication = indication
) {
menuState.expanded = menuState.expanded.not()
}) {
contents()
}
}
Expand Down Expand Up @@ -223,6 +234,7 @@ public fun MenuScope.MenuItem(
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
indication: Indication = LocalIndication.current,
contents: @Composable () -> Unit
) {
Box(
Expand All @@ -234,7 +246,7 @@ public fun MenuScope.MenuItem(
menuState.expanded = false
menuState.currentFocusManager?.clearFocus()
},
indication = LocalIndication.current
indication = indication
)
) {
contents()
Expand Down

0 comments on commit 354e7fd

Please sign in to comment.