Sha256: b7d7c5155e57a73c3873f8a383b501302d28ce1d1996cb87efafc0c34758ff32

Contents?: true

Size: 747 Bytes

Versions: 29

Compression:

Stored size: 747 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

29 entries across 29 versions & 1 rubygems

Version Path
katello-4.7.6 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.5 webpack/components/TypeAhead/helpers/helpers.js
katello-4.8.0.rc2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.4 webpack/components/TypeAhead/helpers/helpers.js
katello-4.8.0.rc1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.3 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.6.2.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.6.2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.0 webpack/components/TypeAhead/helpers/helpers.js
katello-4.6.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.0.rc2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.7.0.rc1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.4.2.2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.4.2.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.4.2 webpack/components/TypeAhead/helpers/helpers.js
katello-4.5.1 webpack/components/TypeAhead/helpers/helpers.js
katello-4.6.0 webpack/components/TypeAhead/helpers/helpers.js
katello-4.6.0.rc2 webpack/components/TypeAhead/helpers/helpers.js