@entur/dropdown 7.2.1 → 7.2.3-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,7 @@ type DropdownListProps<ValueType> = {
21
21
  selectAllItem?: NormalizedDropdownItemType<string>;
22
22
  selectedItems: NormalizedDropdownItemType<ValueType>[];
23
23
  style?: React.CSSProperties;
24
+ readOnly?: boolean;
24
25
  };
25
- export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, isOpen, highlightedIndex, listItems, floatingStyles, setListRef, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
26
+ export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, isOpen, highlightedIndex, listItems, floatingStyles, setListRef, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, readOnly, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
26
27
  export {};
@@ -361,7 +361,7 @@ function _regeneratorRuntime() {
361
361
  }, e;
362
362
  }
363
363
 
364
- var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "isOpen", "highlightedIndex", "listItems", "floatingStyles", "setListRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems"];
364
+ var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "isOpen", "highlightedIndex", "listItems", "floatingStyles", "setListRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "readOnly"];
365
365
  var DropdownList = function DropdownList(_ref) {
366
366
  var _listItems$;
367
367
  var _ref$ariaLabelChosenS = _ref.ariaLabelChosenSingular,
@@ -384,6 +384,8 @@ var DropdownList = function DropdownList(_ref) {
384
384
  selectAllCheckboxState = _ref.selectAllCheckboxState,
385
385
  selectAllItem = _ref.selectAllItem,
386
386
  selectedItems = _ref.selectedItems,
387
+ _ref$readOnly = _ref.readOnly,
388
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
387
389
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
388
390
  var isMultiselect = selectAllItem !== undefined;
389
391
  var isNoMatches = !loading && (listItems.length === 0 || (listItems == null ? void 0 : listItems.length) === 1 && (listItems == null || (_listItems$ = listItems[0]) == null ? void 0 : _listItems$.value) === (selectAllItem == null ? void 0 : selectAllItem.value));
@@ -458,10 +460,10 @@ var DropdownList = function DropdownList(_ref) {
458
460
  ref: setListRef,
459
461
  className: 'eds-dropdown__list',
460
462
  style: _extends({}, floatingStyles, {
461
- display: isOpen ? undefined : 'none'
463
+ display: isOpen && !readOnly ? undefined : 'none'
462
464
  }, rest.style)
463
465
  })), function () {
464
- if (!isOpen) {
466
+ if (!isOpen || readOnly) {
465
467
  return null;
466
468
  }
467
469
  if (loading) {
@@ -878,7 +880,7 @@ function getA11yStatusMessage(options) {
878
880
 
879
881
  var _excluded$3 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loading", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
880
882
  var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
881
- var _document, _getInputProps2, _selectedItem$label;
883
+ var _document, _selectedItem$label;
882
884
  var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
883
885
  _ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
884
886
  ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
@@ -1116,9 +1118,6 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1116
1118
  labelId: getLabelProps().id,
1117
1119
  labelProps: getLabelProps(),
1118
1120
  labelTooltip: labelTooltip,
1119
- onBlur: function onBlur() {
1120
- return setInputValue('');
1121
- },
1122
1121
  onClick: function onClick(e) {
1123
1122
  if (e.target === e.currentTarget) {
1124
1123
  var _getInputProps;
@@ -1145,7 +1144,8 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1145
1144
  loading: loading != null ? loading : resolvedItemsLoading,
1146
1145
  loadingText: loadingText,
1147
1146
  noMatchesText: noMatchesText,
1148
- selectedItems: selectedItem !== null ? [selectedItem] : []
1147
+ selectedItems: selectedItem !== null ? [selectedItem] : [],
1148
+ readOnly: readOnly
1149
1149
  })
1150
1150
  }, rest, {
1151
1151
  // Append is not supported as of now
@@ -1154,8 +1154,14 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1154
1154
  className: classNames('eds-dropdown--searchable__selected-item', {
1155
1155
  'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
1156
1156
  }),
1157
- "aria-hidden": "true",
1158
- onClick: (_getInputProps2 = getInputProps()) == null ? void 0 : _getInputProps2.onClick
1157
+ onClick: function onClick(event) {
1158
+ if (!disabled && !readOnly) {
1159
+ var _inputRef$current2, _getInputProps2;
1160
+ (_inputRef$current2 = inputRef.current) == null || _inputRef$current2.focus();
1161
+ (_getInputProps2 = getInputProps()) == null || _getInputProps2.onClick == null || _getInputProps2.onClick(event);
1162
+ }
1163
+ },
1164
+ tabIndex: readOnly ? 0 : -1
1159
1165
  }, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
1160
1166
  className: classNames('eds-dropdown__input eds-form-control', {
1161
1167
  'eds-dropdown__input--hidden': showSelectedItem
@@ -1176,7 +1182,9 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1176
1182
  if (selectedItem !== null) setShowSelectedItem(true);
1177
1183
  },
1178
1184
  onFocus: function onFocus() {
1179
- setShowSelectedItem(false);
1185
+ if (!readOnly) {
1186
+ setShowSelectedItem(false);
1187
+ }
1180
1188
  },
1181
1189
  disabled: disabled,
1182
1190
  readOnly: readOnly,
@@ -1514,7 +1522,8 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1514
1522
  noMatchesText: noMatchesText,
1515
1523
  selectAllCheckboxState: selectAllCheckboxState,
1516
1524
  selectAllItem: selectAll,
1517
- selectedItems: selectedItems
1525
+ selectedItems: selectedItems,
1526
+ readOnly: readOnly
1518
1527
  })
1519
1528
  }, rest), React.createElement("div", {
1520
1529
  className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
@@ -1756,7 +1765,8 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1756
1765
  setListRef: refs.setFloating,
1757
1766
  loading: loading != null ? loading : resolvedItemsLoading,
1758
1767
  loadingText: loadingText,
1759
- selectedItems: selectedItem !== null ? [selectedItem] : []
1768
+ selectedItems: selectedItem !== null ? [selectedItem] : [],
1769
+ readOnly: readOnly
1760
1770
  })
1761
1771
  }, rest, {
1762
1772
  // Append is not supported as of now