Sha256: 3ac2a57657ab4045cbc4cc46edf7dc5ae56ac772452517c87ecdbb65799a8eb3

Contents?: true

Size: 775 Bytes

Versions: 57

Compression:

Stored size: 775 Bytes

Contents

import { KEYCODES } from 'foremanReact/common/keyCodes';

const keyPressHandler = (
  e, isOpen, activeItems, highlightedIndex,
  selectItem, userInputValue, onSearch,
) => {
  switch (e.keyCode) {
    case KEYCODES.TAB_KEY:
      if (isOpen && activeItems[highlightedIndex]) {
        selectItem(activeItems[highlightedIndex]);
        e.preventDefault();
      }
      break;

    case KEYCODES.ENTER:
      if (!isOpen || !activeItems[highlightedIndex]) {
        onSearch(userInputValue);
        e.preventDefault();
      }
      break;

    default:
      break;
  }
};

export const getActiveItems = items =>
  items
    .filter(({ disabled, type }) => !disabled && !['header', 'divider'].includes(type))
    .map(({ text }) => text);

export default keyPressHandler;

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
katello-4.3.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.4.0.rc1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0.rc4 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0.rc3 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0.rc2.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0.rc2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.3.0.rc1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.0.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.1.4 webpack/components/TypeAhead/helpers/helpers.js
katello-4.0.3 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.0.1.rc3 webpack/components/TypeAhead/helpers/helpers.js
katello-3.18.5 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.0.1.rc2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.0.rc2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.1.3 webpack/components/TypeAhead/helpers/helpers.js
katello-4.2.0.rc1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.0.2.1 webpack/components/TypeAhead/helpers/helpers.js