Skip to content

Commit

Permalink
All Popup overloads call dismiss on Esc key by default (#712)
Browse files Browse the repository at this point in the history
* Expose root modifier instead of key events

* Use only one element for key input

* Handle Esc by default in existing Popup

* Create onKeyEvent modifier only if needed

* Revert EmptySemanticsElement

* Remove handling Esc key explicitly

* Add dismiss Popup by Esc tests

* Move dismissOnEsc to separate modifier
  • Loading branch information
MatkovIvan authored and igordmn committed Jan 30, 2024
1 parent 1fdc83f commit 868934d
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fun DropdownMenu(
onDismissRequest = onDismissRequest,
popupPositionProvider = popupPositionProvider,
onKeyEvent = {
handlePopupOnKeyEvent(it, onDismissRequest, focusManager!!, inputModeManager!!)
handlePopupOnKeyEvent(it, focusManager!!, inputModeManager!!)
},
) {
focusManager = LocalFocusManager.current
Expand Down Expand Up @@ -195,21 +195,17 @@ fun DropdownMenuItem(
@ExperimentalComposeUiApi
private fun handlePopupOnKeyEvent(
keyEvent: KeyEvent,
onDismissRequest: () -> Unit,
focusManager: FocusManager,
inputModeManager: InputModeManager
): Boolean {
return if (keyEvent.type == KeyEventType.KeyDown && keyEvent.key == Key.Escape) {
onDismissRequest()
true
} else if (keyEvent.type == KeyEventType.KeyDown) {
when {
keyEvent.key == Key.DirectionDown -> {
return if (keyEvent.type == KeyEventType.KeyDown) {
when (keyEvent.key) {
Key.DirectionDown -> {
inputModeManager.requestInputMode(InputMode.Keyboard)
focusManager.moveFocus(FocusDirection.Next)
true
}
keyEvent.key == Key.DirectionUp -> {
Key.DirectionUp -> {
inputModeManager.requestInputMode(InputMode.Keyboard)
focusManager.moveFocus(FocusDirection.Previous)
true
Expand Down

0 comments on commit 868934d

Please sign in to comment.