Skip to content

Commit

Permalink
Fix focus manager not be remembered and submenu can't closed by left …
Browse files Browse the repository at this point in the history
…arrow key (#161)

Fix focus manager not be remembered and submenu cam not closed by left arrow key

Co-authored-by: Sebastiano Poggi <[email protected]>
  • Loading branch information
devkanro and rock3r authored Oct 10, 2023
1 parent 9589ee7 commit 89934c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/src/main/kotlin/org/jetbrains/jewel/Dropdown.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ internal fun DropdownMenu(
density = density,
)

var focusManager: FocusManager? by mutableStateOf(null)
var inputModeManager: InputModeManager? by mutableStateOf(null)
var focusManager: FocusManager? by remember { mutableStateOf(null) }
var inputModeManager: InputModeManager? by remember { mutableStateOf(null) }
val menuManager = remember(onDismissRequest) {
MenuManager(onDismissRequest = onDismissRequest)
}
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/kotlin/org/jetbrains/jewel/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
import org.jetbrains.jewel.CommonStateBitMask.Active
import org.jetbrains.jewel.CommonStateBitMask.Enabled
import org.jetbrains.jewel.CommonStateBitMask.Focused
import org.jetbrains.jewel.CommonStateBitMask.Hovered
import org.jetbrains.jewel.CommonStateBitMask.Pressed
import org.jetbrains.jewel.CommonStateBitMask.Selected
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.foundation.border
import org.jetbrains.jewel.foundation.onHover
Expand Down Expand Up @@ -356,7 +361,7 @@ fun MenuSubmenuItem(
is PressInteraction.Press -> itemState = itemState.copy(pressed = true)
is PressInteraction.Cancel, is PressInteraction.Release -> itemState = itemState.copy(pressed = false)
is HoverInteraction.Enter -> {
itemState = itemState.copy(hovered = true)
itemState = itemState.copy(hovered = true, selected = true)
focusRequester.requestFocus()
}

Expand Down Expand Up @@ -479,8 +484,8 @@ internal fun Submenu(
density = density,
)

var focusManager: FocusManager? by mutableStateOf(null)
var inputModeManager: InputModeManager? by mutableStateOf(null)
var focusManager: FocusManager? by remember { mutableStateOf(null) }
var inputModeManager: InputModeManager? by remember { mutableStateOf(null) }
val parentMenuManager = LocalMenuManager.current
val menuManager = remember(parentMenuManager, onDismissRequest) {
parentMenuManager.submenuManager(onDismissRequest)
Expand Down Expand Up @@ -556,12 +561,6 @@ value class MenuItemState(val state: ULong) : SelectableComponentState {

companion object {

private val Enabled = 1UL shl 0
private val Focused = 1UL shl 1
private val Hovered = 1UL shl 2
private val Pressed = 1UL shl 3
private val Selected = 1UL shl 4

fun of(
selected: Boolean,
enabled: Boolean,
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/kotlin/org/jetbrains/jewel/RadioButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.jetbrains.jewel.CommonStateBitMask.Enabled
import org.jetbrains.jewel.CommonStateBitMask.Focused
import org.jetbrains.jewel.CommonStateBitMask.Hovered
import org.jetbrains.jewel.CommonStateBitMask.Pressed
import org.jetbrains.jewel.CommonStateBitMask.Selected
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.styling.RadioButtonStyle

Expand Down Expand Up @@ -249,10 +250,6 @@ value class RadioButtonState(val state: ULong) : SelectableComponentState {

companion object {

private const val SELECTED_BIT_OFFSET = CommonStateBitMask.FIRST_AVAILABLE_OFFSET

private val Selected = 1UL shl SELECTED_BIT_OFFSET

fun of(
selected: Boolean,
enabled: Boolean = true,
Expand Down

0 comments on commit 89934c1

Please sign in to comment.