Sha256: f5bea6eee8e1e0ee07979ea98ebe7d2ce96eb4bc2c98afbb51a3990cf6f2b077

Contents?: true

Size: 1.61 KB

Versions: 70

Compression:

Stored size: 1.61 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { Dropdown, MenuItem } from 'patternfly-react';

const TypeAheadItems = ({
  items, activeItems, getItemProps, highlightedIndex,
}) => (
  <Dropdown.Menu className="typeahead-dropdown">
    {items.map(({ text, type, disabled = false }, index) => {
      if (type === 'header') {
        return (
          <MenuItem key={text} header>
            {text}
          </MenuItem>
        );
      }

      if (type === 'divider') {
        // eslint-disable-next-line react/no-array-index-key
        return <MenuItem key={`divider-${index}`} divider />;
      }

      if (disabled) {
        return (
          <MenuItem key={text} disabled>
            {text}
          </MenuItem>
        );
      }

      const itemProps = getItemProps({
        index: activeItems.indexOf(text),
        item: text,
        active: activeItems[highlightedIndex] === text,
        onClick: (e) => {
          // At this point the event.defaultPrevented
          // is already set to true by react-bootstrap
          // MenuItem. We need to set it back to false
          // So downshift will execute it's own handler
          e.defaultPrevented = false;
        },
      });

      return (
        <MenuItem {...itemProps} key={text}>
          {text}
        </MenuItem>
      );
    })}
  </Dropdown.Menu>
);

TypeAheadItems.propTypes = {
  items: PropTypes.arrayOf(PropTypes.object).isRequired,
  activeItems: PropTypes.arrayOf(PropTypes.string).isRequired,
  highlightedIndex: PropTypes.number.isRequired,
  getItemProps: PropTypes.func.isRequired,
};

export default TypeAheadItems;

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
katello-3.9.0.rc1 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.7.1.1 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.7.1 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.8.0 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.8.0.rc3 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.8.0.rc2 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.7.0 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.8.0.rc1 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.7.0.rc2 webpack/move_to_pf/TypeAhead/TypeAheadItems.js
katello-3.7.0.rc1 webpack/move_to_pf/TypeAhead/TypeAheadItems.js