@canonical/react-components 3.0.0 → 3.1.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.
@@ -64,18 +64,19 @@ const Modal = _ref => {
64
64
  (0, _react.useEffect)(() => {
65
65
  modalRef.current.focus();
66
66
  }, [modalRef]);
67
+ const hasCloseButton = !!close;
67
68
  (0, _react.useEffect)(() => {
68
69
  var _focusableModalElemen;
69
70
  focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
70
71
  let focusIndex = 0;
71
72
  // when the close button is rendered, focus on the 2nd content element and not the close btn.
72
- if (close && focusableModalElements.current.length > 1) {
73
+ if (hasCloseButton && focusableModalElements.current.length > 1) {
73
74
  focusIndex = 1;
74
75
  }
75
76
  (_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0 || _focusableModalElemen.focus({
76
77
  preventScroll: true
77
78
  });
78
- }, [close]);
79
+ }, [hasCloseButton]);
79
80
  (0, _react.useEffect)(() => {
80
81
  const keyDown = event => {
81
82
  const listener = keyListenersMap.get(event.code);
@@ -129,7 +130,7 @@ const Modal = _ref => {
129
130
  }, /*#__PURE__*/_react.default.createElement("h2", {
130
131
  className: "p-modal__title",
131
132
  id: titleId
132
- }, title), !!close && /*#__PURE__*/_react.default.createElement("button", {
133
+ }, title), hasCloseButton && /*#__PURE__*/_react.default.createElement("button", {
133
134
  type: "button",
134
135
  className: "p-modal__close",
135
136
  "aria-label": "Close active modal",
@@ -28,6 +28,7 @@ export type MultiSelectProps = {
28
28
  scrollOverflow?: boolean;
29
29
  isSortedAlphabetically?: boolean;
30
30
  hasSelectedItemsFirst?: boolean;
31
+ id?: string;
31
32
  };
32
33
  type GroupFn = (items: Parameters<typeof getGroupedItems>[0]) => ReturnType<typeof getGroupedItems>;
33
34
  type SortFn = typeof sortAlphabetically;
@@ -178,7 +178,8 @@ const MultiSelect = _ref4 => {
178
178
  variant = "search",
179
179
  scrollOverflow = false,
180
180
  isSortedAlphabetically = true,
181
- hasSelectedItemsFirst = true
181
+ hasSelectedItemsFirst = true,
182
+ id
182
183
  } = _ref4;
183
184
  const buttonRef = (0, _react.useRef)(null);
184
185
  const [isDropdownOpen, setIsDropdownOpen] = (0, _react.useState)(false);
@@ -229,7 +230,7 @@ const MultiSelect = _ref4 => {
229
230
  externallyControlled: true,
230
231
  "aria-controls": dropdownId,
231
232
  "aria-expanded": isDropdownOpen,
232
- id: inputId,
233
+ id: id !== null && id !== void 0 ? id : inputId,
233
234
  role: "combobox",
234
235
  "aria-label": label || placeholder || "Search",
235
236
  disabled: disabled,
@@ -268,7 +269,8 @@ const MultiSelect = _ref4 => {
268
269
  event.stopPropagation();
269
270
  }
270
271
  },
271
- ref: buttonRef
272
+ ref: buttonRef,
273
+ id: id
272
274
  }, /*#__PURE__*/_react.default.createElement("span", {
273
275
  className: "multi-select__condensed-text"
274
276
  }, listSelected && selectedItems.length > 0 ? selectedItemsLabel : placeholder !== null && placeholder !== void 0 ? placeholder : "Select items")),
@@ -323,5 +325,6 @@ MultiSelect.propTypes = {
323
325
  variant: _propTypes.default.oneOf(["condensed", "search"]),
324
326
  scrollOverflow: _propTypes.default.bool,
325
327
  isSortedAlphabetically: _propTypes.default.bool,
326
- hasSelectedItemsFirst: _propTypes.default.bool
328
+ hasSelectedItemsFirst: _propTypes.default.bool,
329
+ id: _propTypes.default.string
327
330
  };
@@ -53,7 +53,8 @@ const SearchExample = exports.SearchExample = {
53
53
  items: [...CondensedExample.args.items.map((item, i) => ({
54
54
  ...item,
55
55
  group: i % 2 === 0 ? "Group 1" : "Group 2"
56
- }))]
56
+ }))],
57
+ id: "search-id"
57
58
  }
58
59
  };
59
60
  const WithDisabledItems = exports.WithDisabledItems = {
@@ -104,6 +105,7 @@ const WithoutSorting = exports.WithoutSorting = {
104
105
  }],
105
106
  variant: "condensed",
106
107
  isSortedAlphabetically: false,
107
- hasSelectedItemsFirst: false
108
+ hasSelectedItemsFirst: false,
109
+ id: "external-id"
108
110
  }
109
111
  };
@@ -58,18 +58,19 @@ export var Modal = _ref => {
58
58
  useEffect(() => {
59
59
  modalRef.current.focus();
60
60
  }, [modalRef]);
61
+ var hasCloseButton = !!close;
61
62
  useEffect(() => {
62
63
  var _focusableModalElemen;
63
64
  focusableModalElements.current = modalRef.current.querySelectorAll(focusableElementSelectors);
64
65
  var focusIndex = 0;
65
66
  // when the close button is rendered, focus on the 2nd content element and not the close btn.
66
- if (close && focusableModalElements.current.length > 1) {
67
+ if (hasCloseButton && focusableModalElements.current.length > 1) {
67
68
  focusIndex = 1;
68
69
  }
69
70
  (_focusableModalElemen = focusableModalElements.current[focusIndex]) === null || _focusableModalElemen === void 0 || _focusableModalElemen.focus({
70
71
  preventScroll: true
71
72
  });
72
- }, [close]);
73
+ }, [hasCloseButton]);
73
74
  useEffect(() => {
74
75
  var keyDown = event => {
75
76
  var listener = keyListenersMap.get(event.code);
@@ -123,7 +124,7 @@ export var Modal = _ref => {
123
124
  }, /*#__PURE__*/React.createElement("h2", {
124
125
  className: "p-modal__title",
125
126
  id: titleId
126
- }, title), !!close && /*#__PURE__*/React.createElement("button", {
127
+ }, title), hasCloseButton && /*#__PURE__*/React.createElement("button", {
127
128
  type: "button",
128
129
  className: "p-modal__close",
129
130
  "aria-label": "Close active modal",
@@ -28,6 +28,7 @@ export type MultiSelectProps = {
28
28
  scrollOverflow?: boolean;
29
29
  isSortedAlphabetically?: boolean;
30
30
  hasSelectedItemsFirst?: boolean;
31
+ id?: string;
31
32
  };
32
33
  type GroupFn = (items: Parameters<typeof getGroupedItems>[0]) => ReturnType<typeof getGroupedItems>;
33
34
  type SortFn = typeof sortAlphabetically;
@@ -171,7 +171,8 @@ export var MultiSelect = _ref4 => {
171
171
  variant = "search",
172
172
  scrollOverflow = false,
173
173
  isSortedAlphabetically = true,
174
- hasSelectedItemsFirst = true
174
+ hasSelectedItemsFirst = true,
175
+ id
175
176
  } = _ref4;
176
177
  var buttonRef = useRef(null);
177
178
  var [isDropdownOpen, setIsDropdownOpen] = useState(false);
@@ -222,7 +223,7 @@ export var MultiSelect = _ref4 => {
222
223
  externallyControlled: true,
223
224
  "aria-controls": dropdownId,
224
225
  "aria-expanded": isDropdownOpen,
225
- id: inputId,
226
+ id: id !== null && id !== void 0 ? id : inputId,
226
227
  role: "combobox",
227
228
  "aria-label": label || placeholder || "Search",
228
229
  disabled: disabled,
@@ -261,7 +262,8 @@ export var MultiSelect = _ref4 => {
261
262
  event.stopPropagation();
262
263
  }
263
264
  },
264
- ref: buttonRef
265
+ ref: buttonRef,
266
+ id: id
265
267
  }, /*#__PURE__*/React.createElement("span", {
266
268
  className: "multi-select__condensed-text"
267
269
  }, listSelected && selectedItems.length > 0 ? selectedItemsLabel : placeholder !== null && placeholder !== void 0 ? placeholder : "Select items")),
@@ -315,5 +317,6 @@ MultiSelect.propTypes = {
315
317
  variant: _pt.oneOf(["condensed", "search"]),
316
318
  scrollOverflow: _pt.bool,
317
319
  isSortedAlphabetically: _pt.bool,
318
- hasSelectedItemsFirst: _pt.bool
320
+ hasSelectedItemsFirst: _pt.bool,
321
+ id: _pt.string
319
322
  };
@@ -49,7 +49,8 @@ export var SearchExample = {
49
49
  variant: "search",
50
50
  items: [...CondensedExample.args.items.map((item, i) => _objectSpread(_objectSpread({}, item), {}, {
51
51
  group: i % 2 === 0 ? "Group 1" : "Group 2"
52
- }))]
52
+ }))],
53
+ id: "search-id"
53
54
  })
54
55
  };
55
56
  export var WithDisabledItems = {
@@ -99,6 +100,7 @@ export var WithoutSorting = {
99
100
  }],
100
101
  variant: "condensed",
101
102
  isSortedAlphabetically: false,
102
- hasSelectedItemsFirst: false
103
+ hasSelectedItemsFirst: false,
104
+ id: "external-id"
103
105
  }
104
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {
@@ -93,7 +93,7 @@
93
93
  "tsc-alias": "1.8.10",
94
94
  "typescript": "5.7.3",
95
95
  "typescript-eslint": "8.24.1",
96
- "vanilla-framework": "4.32.1",
96
+ "vanilla-framework": "4.34.1",
97
97
  "wait-on": "8.0.2",
98
98
  "webpack": "5.98.0"
99
99
  },