( model: MenuModel, $: MenuUpdate, key: string, action: ItemAction | null )
| 1197 | } |
| 1198 | |
| 1199 | const pressKey = ( |
| 1200 | model: MenuModel, |
| 1201 | $: MenuUpdate, |
| 1202 | key: string, |
| 1203 | action: ItemAction | null |
| 1204 | ) => { |
| 1205 | const props = $.props |
| 1206 | if (!props.open) return $.set(model) |
| 1207 | const parent = parentOf($) |
| 1208 | const nav = keys(props.orientation ?? "vertical", rtlOf($, model.rtl)) |
| 1209 | if ( |
| 1210 | key === nav.next || key === nav.previous || key === "Home" || key === "End" |
| 1211 | ) return navigate(model, $, key) |
| 1212 | if (key === "Escape") { |
| 1213 | return props.closeParentOnEsc === true && parent !== undefined |
| 1214 | ? closeTree(model, $, "escape-key", "keyboard") |
| 1215 | : dismiss(model, $, "escape-key", "keyboard") |
| 1216 | } |
| 1217 | if ( |
| 1218 | parent !== undefined && |
| 1219 | key === keys(parent.orientation, rtlOf($, parent.rtl)).close |
| 1220 | ) { |
| 1221 | return dismiss(model, $, "list-navigation", "keyboard") |
| 1222 | } |
| 1223 | const switched = toSibling(model, $, key, nav.open) |
| 1224 | if (switched !== undefined) return switched |
| 1225 | if (key === "Enter") { |
| 1226 | return action === null |
| 1227 | ? $.set(model) |
| 1228 | : activate(model, $, action, "keyboard") |
| 1229 | } |
| 1230 | if (key === " " && !Typeahead.isTyping(model.typeahead)) { |
| 1231 | return $.set(model).evolve({ spaceDown: true }) |
| 1232 | } |
| 1233 | if (key.length === 1 && !filteringOf(props)) return typeKey(model, $, key) |
| 1234 | return $.set(model) |
| 1235 | } |
| 1236 | |
| 1237 | const ownTrigger = (model: MenuModel, props: MenuProps): string | null => |
| 1238 | props.triggerId ?? model.trigger ?? model.triggerElement |
no test coverage detected