How to use the @leafygreen-ui/lib.keyMap.ArrowUp function in @leafygreen-ui/lib

To help you get started, we’ve selected a few @leafygreen-ui/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / leafygreen-ui / packages / mongo-select / src / MongoSelect.tsx View on Github external
const onKeyDown: React.KeyboardEventHandler = e => {
  if ([keyMap.ArrowUp, keyMap.ArrowDown].includes(e.keyCode)) {
    e.preventDefault();
  }
};
github mongodb / leafygreen-ui / packages / menu / src / Menu.tsx View on Github external
function handleKeyDown(e: KeyboardEvent) {
    const filteredRefs = refs.filter(ref => ref !== null);
    let refToFocus: HTMLElement;

    switch (e.keyCode) {
      case keyMap.ArrowDown:
        refToFocus = refs[(refs.indexOf(focused!) + 1) % refs.length];
        refToFocus.focus();
        setFocused(refToFocus);
        break;

      case keyMap.ArrowUp:
        refToFocus =
          refs[(refs.indexOf(focused!) - 1 + refs.length) % refs.length];
        setFocused(refToFocus);
        refToFocus.focus();
        break;

      case keyMap.Tab:
        if (!e.shiftKey && trapLastMenuItem(filteredRefs)) {
          e.preventDefault();
          setFocused(refs[0]);
          refs[0].focus();
        }

        if (e.shiftKey && trapFirstMenuItem()) {
          e.preventDefault();
          filteredRefs[filteredRefs.length - 1].focus();