MCPcopy Create free account
hub / github.com/Effect-TS/effect / pressKey

Function pressKey

packages/effect/src/ui/kit/Menu.ts:1199–1235  ·  view source on GitHub ↗
(
  model: MenuModel,
  $: MenuUpdate,
  key: string,
  action: ItemAction | null
)

Source from the content-addressed store, hash-verified

1197}
1198
1199const 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
1237const ownTrigger = (model: MenuModel, props: MenuProps): string | null =>
1238 props.triggerId ?? model.trigger ?? model.triggerElement

Callers 1

Menu.tsFile · 0.70

Calls 12

closeTreeFunction · 0.85
toSiblingFunction · 0.85
filteringOfFunction · 0.85
parentOfFunction · 0.70
keysFunction · 0.70
rtlOfFunction · 0.70
navigateFunction · 0.70
dismissFunction · 0.70
activateFunction · 0.70
typeKeyFunction · 0.70
setMethod · 0.65
evolveMethod · 0.65

Tested by

no test coverage detected