Skip to content

Commit 868934d

Browse files
MatkovIvanigordmn
authored andcommitted
All Popup overloads call dismiss on Esc key by default (#712)
* 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
1 parent 1fdc83f commit 868934d

File tree

1 file changed

+5
-9
lines changed
  • compose/material3/material3/src/skikoMain/kotlin/androidx/compose/material3

1 file changed

+5
-9
lines changed

compose/material3/material3/src/skikoMain/kotlin/androidx/compose/material3/SkikoMenu.skiko.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fun DropdownMenu(
124124
onDismissRequest = onDismissRequest,
125125
popupPositionProvider = popupPositionProvider,
126126
onKeyEvent = {
127-
handlePopupOnKeyEvent(it, onDismissRequest, focusManager!!, inputModeManager!!)
127+
handlePopupOnKeyEvent(it, focusManager!!, inputModeManager!!)
128128
},
129129
) {
130130
focusManager = LocalFocusManager.current
@@ -195,21 +195,17 @@ fun DropdownMenuItem(
195195
@ExperimentalComposeUiApi
196196
private fun handlePopupOnKeyEvent(
197197
keyEvent: KeyEvent,
198-
onDismissRequest: () -> Unit,
199198
focusManager: FocusManager,
200199
inputModeManager: InputModeManager
201200
): Boolean {
202-
return if (keyEvent.type == KeyEventType.KeyDown && keyEvent.key == Key.Escape) {
203-
onDismissRequest()
204-
true
205-
} else if (keyEvent.type == KeyEventType.KeyDown) {
206-
when {
207-
keyEvent.key == Key.DirectionDown -> {
201+
return if (keyEvent.type == KeyEventType.KeyDown) {
202+
when (keyEvent.key) {
203+
Key.DirectionDown -> {
208204
inputModeManager.requestInputMode(InputMode.Keyboard)
209205
focusManager.moveFocus(FocusDirection.Next)
210206
true
211207
}
212-
keyEvent.key == Key.DirectionUp -> {
208+
Key.DirectionUp -> {
213209
inputModeManager.requestInputMode(InputMode.Keyboard)
214210
focusManager.moveFocus(FocusDirection.Previous)
215211
true

0 commit comments

Comments
 (0)