@kaizen/components 1.79.0 → 1.79.1

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.
@@ -52,8 +52,9 @@ var Select = function (_a) {
52
52
  _c = _a.placeholder,
53
53
  placeholder = _c === void 0 ? '' : _c,
54
54
  isDisabled = _a.isDisabled,
55
+ onSelectionChange = _a.onSelectionChange,
55
56
  portalContainerId = _a.portalContainerId,
56
- restProps = tslib.__rest(_a, ["label", "items", "id", "trigger", "children", "status", "validationMessage", "isReversed", "isFullWidth", "disabledValues", "classNameOverride", "selectedKey", "description", "placeholder", "isDisabled", "portalContainerId"]);
57
+ restProps = tslib.__rest(_a, ["label", "items", "id", "trigger", "children", "status", "validationMessage", "isReversed", "isFullWidth", "disabledValues", "classNameOverride", "selectedKey", "description", "placeholder", "isDisabled", "onSelectionChange", "portalContainerId"]);
57
58
  var refs = reactDom.useFloating().refs;
58
59
  var triggerRef = refs.reference;
59
60
  var fallbackId = React.useId();
@@ -70,7 +71,10 @@ var Select = function (_a) {
70
71
  selectedKey: typeof selectedKey === 'number' ? selectedKey.toString() : selectedKey,
71
72
  description: description,
72
73
  placeholder: placeholder,
73
- isDisabled: isDisabled
74
+ isDisabled: isDisabled,
75
+ onSelectionChange: onSelectionChange ? function (key) {
76
+ return onSelectionChange(key);
77
+ } : undefined
74
78
  }, restProps);
75
79
  var state = select.useSelectState(ariaSelectProps);
76
80
  var _d = select$1.useSelect(ariaSelectProps, state, triggerRef),
@@ -44,8 +44,9 @@ const Select = /*#__PURE__*/function () {
44
44
  _c = _a.placeholder,
45
45
  placeholder = _c === void 0 ? '' : _c,
46
46
  isDisabled = _a.isDisabled,
47
+ onSelectionChange = _a.onSelectionChange,
47
48
  portalContainerId = _a.portalContainerId,
48
- restProps = __rest(_a, ["label", "items", "id", "trigger", "children", "status", "validationMessage", "isReversed", "isFullWidth", "disabledValues", "classNameOverride", "selectedKey", "description", "placeholder", "isDisabled", "portalContainerId"]);
49
+ restProps = __rest(_a, ["label", "items", "id", "trigger", "children", "status", "validationMessage", "isReversed", "isFullWidth", "disabledValues", "classNameOverride", "selectedKey", "description", "placeholder", "isDisabled", "onSelectionChange", "portalContainerId"]);
49
50
  var refs = useFloating().refs;
50
51
  var triggerRef = refs.reference;
51
52
  var fallbackId = useId();
@@ -62,7 +63,10 @@ const Select = /*#__PURE__*/function () {
62
63
  selectedKey: typeof selectedKey === 'number' ? selectedKey.toString() : selectedKey,
63
64
  description: description,
64
65
  placeholder: placeholder,
65
- isDisabled: isDisabled
66
+ isDisabled: isDisabled,
67
+ onSelectionChange: onSelectionChange ? function (key) {
68
+ return onSelectionChange(key);
69
+ } : undefined
66
70
  }, restProps);
67
71
  var state = useSelectState(ariaSelectProps);
68
72
  var _d = useSelect(ariaSelectProps, state, triggerRef),
@@ -5,7 +5,7 @@ import { type Key } from '@react-types/shared';
5
5
  import { type OverrideClassName } from "../../types/OverrideClassName";
6
6
  import { type SelectPopoverContentsProps, type SelectToggleProps } from './subcomponents';
7
7
  import { type SelectItem, type SelectOption } from './types';
8
- type OmittedAriaSelectProps = 'children' | 'items';
8
+ type OmittedAriaSelectProps = 'children' | 'items' | 'onSelectionChange';
9
9
  export type SelectProps<Option extends SelectOption = SelectOption> = {
10
10
  /**
11
11
  * Item objects in the collection.
@@ -45,13 +45,17 @@ export type SelectProps<Option extends SelectOption = SelectOption> = {
45
45
  * Use the `labelText` prop to provide a concise name, and the `description` prop for any help text.
46
46
  */
47
47
  placeholder?: string;
48
+ /**
49
+ * Handler that is called when the selection changes.
50
+ */
51
+ onSelectionChange?: (key: Key) => void;
48
52
  } & OverrideClassName<Omit<AriaSelectProps<Option>, OmittedAriaSelectProps>>;
49
53
  /**
50
54
  * {@link https://cultureamp.atlassian.net/wiki/spaces/DesignSystem/pages/3081896474/Select Guidance} |
51
55
  * {@link https://cultureamp.design/?path=/docs/components-select--docs Storybook}
52
56
  */
53
57
  export declare const Select: {
54
- <Option extends SelectOption = SelectOption>({ label, items, id: propsId, trigger, children, status, validationMessage, isReversed, isFullWidth, disabledValues, classNameOverride, selectedKey, description, placeholder, isDisabled, portalContainerId, ...restProps }: SelectProps<Option>): JSX.Element;
58
+ <Option extends SelectOption = SelectOption>({ label, items, id: propsId, trigger, children, status, validationMessage, isReversed, isFullWidth, disabledValues, classNameOverride, selectedKey, description, placeholder, isDisabled, onSelectionChange, portalContainerId, ...restProps }: SelectProps<Option>): JSX.Element;
55
59
  displayName: string;
56
60
  Section: {
57
61
  <Option extends SelectOption = SelectOption>({ section, }: import("./subcomponents").ListBoxSectionProps<Option>): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaizen/components",
3
- "version": "1.79.0",
3
+ "version": "1.79.1",
4
4
  "description": "Kaizen component library",
5
5
  "author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
6
6
  "homepage": "https://cultureamp.design",
@@ -25,7 +25,7 @@ import { getDisabledKeysFromItems } from './utils/getDisabledKeysFromItems'
25
25
  import { transformSelectItemToCollectionElement } from './utils/transformSelectItemToCollectionElement'
26
26
  import styles from './Select.module.scss'
27
27
 
28
- type OmittedAriaSelectProps = 'children' | 'items'
28
+ type OmittedAriaSelectProps = 'children' | 'items' | 'onSelectionChange'
29
29
 
30
30
  export type SelectProps<Option extends SelectOption = SelectOption> = {
31
31
  /**
@@ -70,6 +70,10 @@ export type SelectProps<Option extends SelectOption = SelectOption> = {
70
70
  * Use the `labelText` prop to provide a concise name, and the `description` prop for any help text.
71
71
  */
72
72
  placeholder?: string
73
+ /**
74
+ * Handler that is called when the selection changes.
75
+ */
76
+ onSelectionChange?: (key: Key) => void
73
77
  } & OverrideClassName<Omit<AriaSelectProps<Option>, OmittedAriaSelectProps>>
74
78
 
75
79
  /**
@@ -92,6 +96,7 @@ export const Select = <Option extends SelectOption = SelectOption>({
92
96
  description,
93
97
  placeholder = '',
94
98
  isDisabled,
99
+ onSelectionChange,
95
100
  portalContainerId,
96
101
  ...restProps
97
102
  }: SelectProps<Option>): JSX.Element => {
@@ -114,6 +119,7 @@ export const Select = <Option extends SelectOption = SelectOption>({
114
119
  description,
115
120
  placeholder,
116
121
  isDisabled,
122
+ onSelectionChange: onSelectionChange ? (key) => onSelectionChange(key!) : undefined,
117
123
  ...restProps,
118
124
  }
119
125
 
@@ -45,23 +45,29 @@ export const OnButton: Story = {
45
45
  const button = canvas.queryByRole('button') ?? canvas.getByRole('link')
46
46
 
47
47
  await step('Hover shows', async () => {
48
- await waitFor(() => userEvent.unhover(button))
48
+ await waitFor(() => userEvent.click(canvasElement)) // needed to refocus the browser window
49
+
49
50
  await userEvent.hover(button)
50
- const tooltip = canvas.findByRole('tooltip')
51
- await expect(await tooltip).toBeInTheDocument()
52
- await expect((await tooltip).checkVisibility()).toBe(true)
51
+ await expect(await canvas.findByRole('tooltip')).toBeInTheDocument()
52
+ await expect((await canvas.findByRole('tooltip')).checkVisibility()).toBe(true)
53
53
  await expect(button).toHaveAttribute('aria-describedby', canvas.getByRole('tooltip').id)
54
54
  await userEvent.unhover(button)
55
55
  })
56
56
 
57
57
  await step('Focus shows', async () => {
58
+ await waitFor(() => userEvent.click(canvasElement)) // needed to refocus the browser window
59
+
58
60
  await userEvent.tab() // focus
59
- await waitFor(() => expect(canvas.getByRole('tooltip')).toBeVisible())
61
+ await expect((await canvas.findByRole('tooltip')).checkVisibility()).toBe(true)
62
+ await expect(await canvas.findByRole('tooltip')).toBeInTheDocument()
60
63
  await userEvent.tab() // unfocus
61
- await waitFor(() => expect(canvas.queryByRole('tooltip')).toBeNull())
64
+ waitFor(() => expect(canvas.queryByRole('tooltip')).toBeNull())
65
+ waitFor(async () => expect(await canvas.queryByText('Tooltip content')).toBeNull())
62
66
  })
63
67
 
64
68
  await step('Escape closes', async () => {
69
+ await waitFor(() => userEvent.click(canvasElement)) // needed to refocus the browser window
70
+
65
71
  await userEvent.tab() // focus
66
72
  await waitFor(() => expect(canvas.getByRole('tooltip')).toBeVisible())
67
73
  await userEvent.keyboard('{Escape}')