@kaizen/components 1.78.2 → 1.78.4

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.
Files changed (36) hide show
  1. package/dist/cjs/src/Filter/FilterMultiSelect/FilterMultiSelect.cjs +11 -4
  2. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.cjs +1 -1
  3. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.css.cjs +9 -0
  4. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.cjs +1 -1
  5. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/{MenuPopup.module.scss.cjs → MenuPopup.module.css.cjs} +1 -1
  6. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/ResponsiveMenuPopup.cjs +91 -0
  7. package/dist/esm/src/Filter/FilterMultiSelect/FilterMultiSelect.mjs +12 -5
  8. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.mjs +1 -1
  9. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.css.mjs +7 -0
  10. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.mjs +1 -1
  11. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.module.css.mjs +4 -0
  12. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/ResponsiveMenuPopup.mjs +85 -0
  13. package/dist/styles.css +8652 -8646
  14. package/dist/types/Filter/FilterMultiSelect/FilterMultiSelect.d.ts +7 -1
  15. package/dist/types/Filter/FilterMultiSelect/_docs/MockData.d.ts +1 -0
  16. package/dist/types/Filter/FilterMultiSelect/subcomponents/MenuPopup/ResponsiveMenuPopup.d.ts +22 -0
  17. package/dist/types/Filter/FilterMultiSelect/subcomponents/MenuPopup/index.d.ts +1 -0
  18. package/package.json +1 -1
  19. package/src/Filter/FilterBar/subcomponents/FilterBarMultiSelect/FilterBarMultiSelect.spec.tsx +1 -0
  20. package/src/Filter/FilterMultiSelect/FilterMultiSelect.tsx +10 -4
  21. package/src/Filter/FilterMultiSelect/_docs/FilterMultiSelect.mdx +9 -1
  22. package/src/Filter/FilterMultiSelect/_docs/FilterMultiSelect.stories.tsx +113 -2
  23. package/src/Filter/FilterMultiSelect/_docs/MockData.ts +39 -0
  24. package/src/Filter/FilterMultiSelect/context/MenuTriggerProvider/MenuTriggerProvider.spec.tsx +2 -18
  25. package/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.css +20 -0
  26. package/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.tsx +1 -1
  27. package/src/Filter/FilterMultiSelect/subcomponents/ListBoxSection/ListBoxSection.module.scss +1 -0
  28. package/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.module.css +21 -0
  29. package/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.tsx +1 -1
  30. package/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/ResponsiveMenuPopup.tsx +115 -0
  31. package/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/index.ts +1 -0
  32. package/dist/cjs/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.scss.cjs +0 -9
  33. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.scss.mjs +0 -7
  34. package/dist/esm/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.module.scss.mjs +0 -4
  35. package/src/Filter/FilterMultiSelect/subcomponents/ListBox/ListBox.module.scss +0 -23
  36. package/src/Filter/FilterMultiSelect/subcomponents/MenuPopup/MenuPopup.module.scss +0 -22
@@ -15,11 +15,13 @@ type SelectionProps = {
15
15
  export type FilterMultiSelectProps = {
16
16
  trigger: (value?: MenuTriggerProviderContextType) => React.ReactNode;
17
17
  children: (value?: SelectionProviderContextType) => React.ReactNode;
18
+ /** Replaces the MenuPopup. Should only be used for changing how the floating element is positioned, ie: with the `<ResponsiveMenuPopup />` primitive. */
19
+ customMenuPopup?: React.ComponentType<MenuPopupProps>;
18
20
  triggerRef?: React.RefObject<HTMLButtonElement>;
19
21
  className?: string;
20
22
  } & Omit<MenuPopupProps, 'children'> & Omit<MenuTriggerProviderProps, 'children'> & SelectionProps;
21
23
  export declare const FilterMultiSelect: {
22
- ({ trigger, children, isOpen, defaultOpen, onOpenChange, isLoading, loadingSkeleton, label, items, selectedKeys, defaultSelectedKeys, onSelectionChange, selectionMode, onSearchInputChange, triggerRef, className, }: FilterMultiSelectProps): JSX.Element;
24
+ ({ trigger, children, customMenuPopup, isOpen, defaultOpen, onOpenChange, isLoading, loadingSkeleton, label, items, selectedKeys, defaultSelectedKeys, onSelectionChange, selectionMode, onSearchInputChange, triggerRef, className, ...restProps }: FilterMultiSelectProps): JSX.Element;
23
25
  displayName: string;
24
26
  TriggerButton: {
25
27
  ({ selectedOptionLabels, label, classNameOverride, labelCharacterLimitBeforeTruncate, }: import("./subcomponents/Trigger").FilterTriggerButtonProps): JSX.Element;
@@ -70,5 +72,9 @@ export declare const FilterMultiSelect: {
70
72
  ({ children, ...restProps }: import("./subcomponents/NoResults").NoResultsProps): JSX.Element;
71
73
  displayName: string;
72
74
  };
75
+ ResponsiveMenuPopup: {
76
+ ({ children, floatingConfig, classNameOverride, isLoading, loadingSkeleton, ...restProps }: import("./subcomponents/MenuPopup").ResponsiveMenuPopupProps): JSX.Element;
77
+ displayName: string;
78
+ };
73
79
  };
74
80
  export {};
@@ -8,3 +8,4 @@ export declare const locationDemographicValues: {
8
8
  demographicValueId: string;
9
9
  label: string;
10
10
  }[];
11
+ export declare const mockManyItems: ItemType[];
@@ -0,0 +1,22 @@
1
+ import { type HTMLAttributes } from 'react';
2
+ import { type UseFloatingOptions } from '@floating-ui/react-dom';
3
+ import { type OverrideClassName } from "../../../../types/OverrideClassName";
4
+ import { type MenuPopupProps } from './MenuPopup';
5
+ export type FloatingConfig = Pick<UseFloatingOptions, 'placement' | 'strategy' | 'whileElementsMounted'> & {
6
+ /** Whether the component should automatically resize based on the available window height.
7
+ * @default true
8
+ */
9
+ shouldResize?: boolean;
10
+ /** Whether the component should automatically flip to the top of the input based on the available window height.
11
+ * @default true
12
+ */
13
+ shouldFlip?: boolean;
14
+ };
15
+ export type ResponsiveMenuPopupProps = MenuPopupProps & {
16
+ floatingConfig?: FloatingConfig;
17
+ } & OverrideClassName<HTMLAttributes<HTMLDivElement>>;
18
+ /** This is a popup primitive that can be used with the FilterMultiSelect when there are overflow issues with the original implementation. This uses the floating-ui */
19
+ export declare const ResponsiveMenuPopup: {
20
+ ({ children, floatingConfig, classNameOverride, isLoading, loadingSkeleton, ...restProps }: ResponsiveMenuPopupProps): JSX.Element;
21
+ displayName: string;
22
+ };
@@ -1 +1,2 @@
1
1
  export * from './MenuPopup';
2
+ export * from './ResponsiveMenuPopup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaizen/components",
3
- "version": "1.78.2",
3
+ "version": "1.78.4",
4
4
  "description": "Kaizen component library",
5
5
  "author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
6
6
  "homepage": "https://cultureamp.design",
@@ -180,6 +180,7 @@ describe('<FilterBarMultiSelect />', () => {
180
180
  })
181
181
 
182
182
  await user.click(getByRole('option', { name: 'Fruit Jelly' }))
183
+ await user.keyboard('{Escape}')
183
184
  await waitFor(() => {
184
185
  expect(getByRole('button', { name: 'Toppings : Pearls, Fruit Jelly' })).toBeInTheDocument()
185
186
  })
@@ -13,7 +13,7 @@ import { ListBox } from './subcomponents/ListBox'
13
13
  import { ListBoxSection } from './subcomponents/ListBoxSection'
14
14
  import { LoadMoreButton } from './subcomponents/LoadMoreButton'
15
15
  import { MenuFooter, MenuLoadingSkeleton } from './subcomponents/MenuLayout'
16
- import { MenuPopup, type MenuPopupProps } from './subcomponents/MenuPopup'
16
+ import { MenuPopup, ResponsiveMenuPopup, type MenuPopupProps } from './subcomponents/MenuPopup'
17
17
  import { MultiSelectOption } from './subcomponents/MultiSelectOption'
18
18
  import { NoResults } from './subcomponents/NoResults'
19
19
  import { SearchInput } from './subcomponents/SearchInput'
@@ -35,6 +35,8 @@ type SelectionProps = {
35
35
  export type FilterMultiSelectProps = {
36
36
  trigger: (value?: MenuTriggerProviderContextType) => React.ReactNode
37
37
  children: (value?: SelectionProviderContextType) => React.ReactNode // the content of the menu
38
+ /** Replaces the MenuPopup. Should only be used for changing how the floating element is positioned, ie: with the `<ResponsiveMenuPopup />` primitive. */
39
+ customMenuPopup?: React.ComponentType<MenuPopupProps>
38
40
  triggerRef?: React.RefObject<HTMLButtonElement>
39
41
  className?: string
40
42
  } & Omit<MenuPopupProps, 'children'> &
@@ -44,6 +46,7 @@ export type FilterMultiSelectProps = {
44
46
  export const FilterMultiSelect = ({
45
47
  trigger,
46
48
  children,
49
+ customMenuPopup,
47
50
  isOpen,
48
51
  defaultOpen,
49
52
  onOpenChange,
@@ -58,9 +61,11 @@ export const FilterMultiSelect = ({
58
61
  onSearchInputChange,
59
62
  triggerRef,
60
63
  className,
64
+ ...restProps
61
65
  }: FilterMultiSelectProps): JSX.Element => {
66
+ const MenuComponent = customMenuPopup ?? MenuPopup
62
67
  const menuTriggerProps = { isOpen, defaultOpen, onOpenChange, triggerRef }
63
- const menuPopupProps = { isLoading, loadingSkeleton }
68
+ const menuPopupProps = { isLoading, loadingSkeleton, ...restProps }
64
69
  const disabledKeys: Selection = new Set(
65
70
  items?.filter((item) => item.isDisabled === true).map((disabledItem) => disabledItem.value),
66
71
  )
@@ -79,11 +84,11 @@ export const FilterMultiSelect = ({
79
84
  <MenuTriggerProvider {...menuTriggerProps}>
80
85
  <div className={className}>
81
86
  <MenuTriggerConsumer>{trigger}</MenuTriggerConsumer>
82
- <MenuPopup {...menuPopupProps}>
87
+ <MenuComponent aria-label={label} {...menuPopupProps}>
83
88
  <SelectionProvider {...selectionProps}>
84
89
  <SelectionConsumer>{children}</SelectionConsumer>
85
90
  </SelectionProvider>
86
- </MenuPopup>
91
+ </MenuComponent>
87
92
  </div>
88
93
  </MenuTriggerProvider>
89
94
  )
@@ -104,3 +109,4 @@ FilterMultiSelect.MenuFooter = MenuFooter // For layout
104
109
  FilterMultiSelect.MenuLoadingSkeleton = MenuLoadingSkeleton // Menu Loading Skeleton example
105
110
  FilterMultiSelect.LoadMoreButton = LoadMoreButton
106
111
  FilterMultiSelect.NoResults = NoResults
112
+ FilterMultiSelect.ResponsiveMenuPopup = ResponsiveMenuPopup
@@ -1,4 +1,4 @@
1
- import { Controls, Meta, Canvas } from '@storybook/blocks'
1
+ import { Controls, Meta, Canvas, DocsStory } from '@storybook/blocks'
2
2
  import { ResourceLinks, KAIOInstallation, NoClipCanvas } from '~storybook/components'
3
3
  import * as FilterMultiSelectStories from './FilterMultiSelect.stories'
4
4
 
@@ -30,6 +30,14 @@ The FilterMultiSelect is a component relies heavily on consumer implemntation. I
30
30
 
31
31
  <Canvas of={FilterMultiSelectStories.WithSectionHeaders} />
32
32
 
33
+ ### With customMenuPopup component
34
+
35
+ You can replace the `MenuPopup` component within the FilterMultiSelect to allow flexibility in how the popup's placement is determined. While the default behavior should satisfy most scenarios, this can be used when there is limited vertical space available in the viewport.
36
+
37
+ <Canvas of={FilterMultiSelectStories.AboveIfAvailable} />
38
+
39
+ For convenience, a primitive called `ResponsiveMenuPopup` that can be accessed via dot notation that will automatically adjust the placement and size of the popup based on the available window height. This implementation uses `floating-ui` and the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) instead of `react-aria` hooks. It also locks scroll when the popup is active.
40
+
33
41
  ### Async
34
42
 
35
43
  The following is an example of how you may create an async FilterMultiSelect using `@tanstack/react-query`.
@@ -1,11 +1,13 @@
1
1
  import React, { useState } from 'react'
2
2
  import type { Selection } from '@react-types/shared'
3
3
  import type { Meta, StoryObj } from '@storybook/react'
4
+ import { expect, userEvent, waitFor, within } from '@storybook/test'
4
5
  import isChromatic from 'chromatic'
6
+ import { Card } from '~components/Card'
5
7
  import { InlineNotification } from '~components/Notification'
6
8
  import { TextField } from '~components/TextField'
7
9
  import { FilterMultiSelect, getSelectedOptionLabels } from '..'
8
- import { mockItems } from './MockData'
10
+ import { mockItems, mockManyItems } from './MockData'
9
11
 
10
12
  const IS_CHROMATIC = isChromatic()
11
13
 
@@ -14,7 +16,7 @@ const meta = {
14
16
  component: FilterMultiSelect,
15
17
  parameters: {
16
18
  docs: {
17
- source: { type: 'code' },
19
+ source: { type: 'auto' },
18
20
  },
19
21
  },
20
22
  args: {
@@ -178,6 +180,7 @@ export const WithSectionHeaders: Story = {
178
180
  ...FilterMultiSelectTemplate,
179
181
  args: {
180
182
  isOpen: IS_CHROMATIC || undefined,
183
+ items: mockManyItems,
181
184
  children: (): JSX.Element => (
182
185
  <>
183
186
  <FilterMultiSelect.SearchInput />
@@ -308,3 +311,111 @@ export const WithSectionNotification: Story = {
308
311
  chromatic: { disable: false },
309
312
  },
310
313
  }
314
+
315
+ const sourceCode = `
316
+ <FilterMultiSelect
317
+ {...filterMultiSelectProps}
318
+ customMenuPopup={(props): JSX.Element => (
319
+ // This will replace the default MenuPopup with a custom one. The rest of the component should still be implemented as the FilterMultiSelect pattern.
320
+ <FilterMultiSelect.ResponsiveMenuPopup {...props} />
321
+ )}
322
+ >
323
+ {/* FilterMultiSelect children */}
324
+ </FilterMultiSelect>
325
+ `
326
+
327
+ export const WithContentBelow: Story = {
328
+ ...FilterMultiSelectTemplate,
329
+ decorators: [
330
+ (Story) => (
331
+ <div>
332
+ <Story />
333
+ <Card classNameOverride="mt-24 p-12" isElevated>
334
+ <p>
335
+ Lorem ipsum dolor, sit amet consectetur adipisicing elit. Veritatis libero dolore
336
+ pariatur enim voluptates aperiam, delectus, harum cum earum quibusdam quos porro
337
+ explicabo quisquam sapiente cupiditate quae hic, minus nam.
338
+ </p>
339
+ </Card>
340
+ </div>
341
+ ),
342
+ ],
343
+ parameters: {
344
+ chromatic: {
345
+ disable: false,
346
+ },
347
+ },
348
+ play: async ({ canvasElement, step }) => {
349
+ const canvas = within(canvasElement.parentElement!)
350
+ const triggerButton = await canvas.findByRole('button', {
351
+ name: /Engineer/i,
352
+ })
353
+ await step('Trigger opens the FilterMultiSelect dialog', async () => {
354
+ await userEvent.click(triggerButton)
355
+ await waitFor(() => expect(canvas.getByRole('option', { name: /Front-End/i })).toBeVisible())
356
+ })
357
+ },
358
+ }
359
+
360
+ export const AboveIfAvailable: Story = {
361
+ ...WithSectionNotification,
362
+ name: 'With customMenuPopup and vertical placement',
363
+ parameters: {
364
+ viewport: {
365
+ viewports: {
366
+ LimitedViewportAutoPlace: {
367
+ name: 'Limited vertical space',
368
+ styles: {
369
+ width: '1024px',
370
+ height: '650px',
371
+ },
372
+ },
373
+ },
374
+ defaultViewport: 'LimitedViewportAutoPlace',
375
+ },
376
+ docs: { source: { code: sourceCode } },
377
+ },
378
+ args: {
379
+ customMenuPopup: (props): JSX.Element => <FilterMultiSelect.ResponsiveMenuPopup {...props} />,
380
+ },
381
+ decorators: [
382
+ (Story) => (
383
+ <div>
384
+ <div style={{ height: '80vh', maxHeight: '500px' }}>Content above</div>
385
+ <Story />
386
+ </div>
387
+ ),
388
+ ],
389
+ }
390
+
391
+ export const ShouldResize: Story = {
392
+ ...AboveIfAvailable,
393
+ name: 'With customMenuPopup, vertical placement and resized popup',
394
+ parameters: {
395
+ chromatic: {
396
+ disable: false,
397
+ },
398
+ viewport: {
399
+ viewports: {
400
+ LimitedViewportAutoPlace: {
401
+ name: 'Limited vertical space',
402
+ styles: {
403
+ width: '1024px',
404
+ height: '450px',
405
+ },
406
+ },
407
+ },
408
+ defaultViewport: 'LimitedViewportAutoPlace',
409
+ },
410
+ },
411
+ play: async ({ canvasElement, step }) => {
412
+ const canvas = within(canvasElement.parentElement!)
413
+ const triggerButton = await canvas.findByRole('button', {
414
+ name: /Engineer/i,
415
+ })
416
+ await step('Trigger opens the FilterMultiSelect dialog', async () => {
417
+ await userEvent.click(triggerButton)
418
+ await waitFor(() => expect(canvas.getByRole('dialog')).toBeVisible())
419
+ })
420
+ },
421
+ }
@@ -58,3 +58,42 @@ export const locationDemographicValues = [
58
58
  label: 'London',
59
59
  },
60
60
  ]
61
+
62
+ export const mockManyItems: ItemType[] = [
63
+ { label: 'Front-End', value: 'id-fe', count: '1245' },
64
+ { label: 'Back-End', value: 'id-be', count: '4', isDisabled: true },
65
+ { label: 'SRE', value: 'id-sre', count: '4', isDisabled: true },
66
+ { label: 'Dev-ops', value: 'id-devops' },
67
+ { label: 'Others', value: 'id-others' },
68
+ {
69
+ label: 'Engineer-type-1 has a really really long label',
70
+ value: 'id-type-1',
71
+ },
72
+ {
73
+ label: 'Engineer-type-2 also has a really really long label',
74
+ value: 'id-type-2',
75
+ count: '156',
76
+ },
77
+ { label: 'Engineer-type-3', value: 'id-type-3' },
78
+ {
79
+ label: 'Engineer-type-4',
80
+ value: 'id-type-4',
81
+ count: '4',
82
+ isDisabled: true,
83
+ },
84
+ { label: 'Engineer-type-5', value: 'id-type-5' },
85
+ { label: 'UI Designer', value: 'id-ui', count: '42' },
86
+ { label: 'UX Researcher', value: 'id-ux', count: '15' },
87
+ { label: 'Product Manager', value: 'id-pm', count: '28' },
88
+ { label: 'Project Manager', value: 'id-project', count: '19', isDisabled: true },
89
+ { label: 'Data Scientist', value: 'id-ds', count: '11' },
90
+ { label: 'Machine Learning Engineer', value: 'id-ml', count: '7' },
91
+ { label: 'QA Tester', value: 'id-qa', count: '22' },
92
+ {
93
+ label: 'Technical Writer with documentation expertise',
94
+ value: 'id-tech-writer',
95
+ count: '5',
96
+ },
97
+ { label: 'DevSecOps Engineer', value: 'id-devsecops', count: '3', isDisabled: true },
98
+ { label: 'Cloud Architect', value: 'id-cloud', count: '8' },
99
+ ]
@@ -1,7 +1,6 @@
1
1
  import React from 'react'
2
2
  import { render, screen, waitFor } from '@testing-library/react'
3
3
  import userEvent from '@testing-library/user-event'
4
- import { vi } from 'vitest'
5
4
  import { FilterTriggerButton } from '~components/Filter/FilterMultiSelect/subcomponents/Trigger'
6
5
  import { MenuPopup } from '../../subcomponents/MenuPopup'
7
6
  import { MenuTriggerProvider, type MenuTriggerProviderProps } from './MenuTriggerProvider'
@@ -53,15 +52,11 @@ describe('<MenuTriggerProvider /> - Visual content', () => {
53
52
  rerender(<MenuTriggerProviderWrapper isOpen={false} />)
54
53
  expect(screen.queryByText('menu-content-mock')).not.toBeInTheDocument()
55
54
  })
56
-
57
- it('fires the onOpenChange callback when the trigger is interacted', async () => {
55
+ it('fires the onOpenChange callback on user interaction to close the menu', async () => {
58
56
  const onOpenChange = vi.fn()
59
57
  render(<MenuTriggerProviderWrapper isOpen onOpenChange={onOpenChange} />)
60
58
 
61
- const trigger = screen.getByRole('button', {
62
- name: 'trigger-display-label-mock',
63
- })
64
- await user.click(trigger)
59
+ await user.keyboard('{Escape}')
65
60
 
66
61
  await waitFor(() => {
67
62
  expect(onOpenChange).toBeCalledTimes(1)
@@ -86,17 +81,6 @@ describe('<MenuTriggerProvider /> - Mouse interaction', () => {
86
81
  })
87
82
 
88
83
  describe('Given the menu is opened', () => {
89
- it('is closed when user clicks on the trigger', async () => {
90
- render(<MenuTriggerProviderWrapper defaultOpen />)
91
- const trigger = screen.getByRole('button', {
92
- name: 'trigger-display-label-mock',
93
- })
94
- await user.click(trigger)
95
- await waitFor(() => {
96
- expect(screen.queryByText('menu-content-mock')).not.toBeInTheDocument()
97
- })
98
- })
99
-
100
84
  it('is closed when user clicks outside of the menu', async () => {
101
85
  render(<MenuTriggerProviderWrapper defaultOpen />)
102
86
  await user.click(document.body)
@@ -0,0 +1,20 @@
1
+ .listBox {
2
+ list-style: none;
3
+ padding: var(--spacing-12);
4
+ margin: 0 var(--spacing-12) 0 0;
5
+ display: grid;
6
+ max-height: 22rem;
7
+ overflow-y: auto;
8
+ }
9
+
10
+ .overflown {
11
+ padding-right: var(--spacing-12);
12
+ }
13
+
14
+ .hidden {
15
+ display: none;
16
+ }
17
+
18
+ .noResultsWrapper {
19
+ list-style: none;
20
+ }
@@ -3,7 +3,7 @@ import { type Collection, type Key } from '@react-types/shared'
3
3
  import classnames from 'classnames'
4
4
  import { useSelectionContext } from '../../context/SelectionProvider'
5
5
  import { type MultiSelectItem } from '../../types'
6
- import styles from './ListBox.module.scss'
6
+ import styles from './ListBox.module.css'
7
7
 
8
8
  export type ListBoxItems = {
9
9
  selectedItems: MultiSelectItem[]
@@ -9,6 +9,7 @@
9
9
  }
10
10
 
11
11
  .listBoxSectionHeader {
12
+ position: relative; // this is needed to ensure the VisuallyHidden element doesn't impact the scroll height of the list
12
13
  font-family: $typography-heading-6-font-family;
13
14
  font-size: $typography-heading-6-font-size;
14
15
  font-weight: $typography-heading-6-font-weight;
@@ -0,0 +1,21 @@
1
+ .menuPopup {
2
+ /* from $ca-z-index-dropdown */
3
+ position: absolute;
4
+ z-index: 1000;
5
+ box-sizing: border-box;
6
+ background: var(--color-white);
7
+ color: var(--color-purple-800);
8
+ border-radius: var(--border-solid-border-radius);
9
+ box-shadow: var(--shadow-large-box-shadow);
10
+ padding: var(--spacing-12) 0;
11
+ margin-top: var(--spacing-6);
12
+ text-align: start;
13
+ width: var(--menu-container-width, 294px);
14
+ }
15
+
16
+ .menuPopup[popover]:popover-open {
17
+ max-height: var(--menu-container-height, 500px);
18
+ z-index: unset;
19
+ margin: 0;
20
+ inset: unset;
21
+ }
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import { FocusScope } from '@react-aria/focus'
3
3
  import { DismissButton, useOverlay } from '@react-aria/overlays'
4
4
  import { useMenuTriggerContext } from '../../context'
5
- import styles from './MenuPopup.module.scss'
5
+ import styles from './MenuPopup.module.css'
6
6
 
7
7
  export type MenuPopupProps = {
8
8
  isLoading?: boolean
@@ -0,0 +1,115 @@
1
+ import React, { useEffect, useState, type HTMLAttributes } from 'react'
2
+ import {
3
+ autoPlacement,
4
+ autoUpdate,
5
+ offset,
6
+ size,
7
+ useFloating,
8
+ type UseFloatingOptions,
9
+ } from '@floating-ui/react-dom'
10
+ import classnames from 'classnames'
11
+ import { FocusOn } from 'react-focus-on'
12
+ import { type OverrideClassName } from '~components/types/OverrideClassName'
13
+ import { useMenuTriggerContext } from '../../context'
14
+ import { type MenuPopupProps } from './MenuPopup'
15
+ import styles from './MenuPopup.module.css'
16
+
17
+ export type FloatingConfig = Pick<
18
+ UseFloatingOptions,
19
+ 'placement' | 'strategy' | 'whileElementsMounted'
20
+ > & {
21
+ /** Whether the component should automatically resize based on the available window height.
22
+ * @default true
23
+ */
24
+ shouldResize?: boolean
25
+ /** Whether the component should automatically flip to the top of the input based on the available window height.
26
+ * @default true
27
+ */
28
+ shouldFlip?: boolean
29
+ }
30
+
31
+ export type ResponsiveMenuPopupProps = MenuPopupProps & {
32
+ floatingConfig?: FloatingConfig
33
+ } & OverrideClassName<HTMLAttributes<HTMLDivElement>>
34
+
35
+ /** This is a popup primitive that can be used with the FilterMultiSelect when there are overflow issues with the original implementation. This uses the floating-ui */
36
+ export const ResponsiveMenuPopup = ({
37
+ children,
38
+ floatingConfig = {
39
+ placement: 'bottom-start',
40
+ strategy: 'absolute',
41
+ whileElementsMounted: autoUpdate,
42
+ shouldFlip: true,
43
+ shouldResize: true,
44
+ },
45
+ classNameOverride,
46
+ isLoading,
47
+ loadingSkeleton,
48
+ ...restProps
49
+ }: ResponsiveMenuPopupProps): JSX.Element => {
50
+ const [floatingElement, setFloatingElement] = useState<HTMLDivElement | null>(null)
51
+ const { menuTriggerState, buttonRef } = useMenuTriggerContext()
52
+ const referenceElement = buttonRef.current
53
+
54
+ const { floatingStyles, update } = useFloating({
55
+ elements: {
56
+ reference: referenceElement,
57
+ floating: floatingElement,
58
+ },
59
+ middleware: [
60
+ offset(6),
61
+ floatingConfig.shouldFlip &&
62
+ autoPlacement({ allowedPlacements: ['bottom-start', 'top-start'] }),
63
+ floatingConfig.shouldResize &&
64
+ size({
65
+ apply({ availableHeight, elements }) {
66
+ Object.assign(elements.floating.style, {
67
+ maxHeight: Math.max(250, Math.min(availableHeight - 12, 500)) + 'px',
68
+ })
69
+ },
70
+ }),
71
+ ],
72
+ ...floatingConfig,
73
+ })
74
+
75
+ const handleReturnFocus = (): void => {
76
+ requestAnimationFrame(() => {
77
+ buttonRef.current?.focus()
78
+ })
79
+ }
80
+
81
+ useEffect(() => {
82
+ if (floatingElement && referenceElement) {
83
+ floatingElement.showPopover?.()
84
+ update()
85
+ }
86
+ }, [floatingElement, referenceElement, update])
87
+
88
+ return menuTriggerState.isOpen ? (
89
+ <FocusOn
90
+ enabled={menuTriggerState.isOpen}
91
+ scrollLock={true}
92
+ returnFocus={false}
93
+ onClickOutside={menuTriggerState.close}
94
+ onEscapeKey={menuTriggerState.close}
95
+ onDeactivation={handleReturnFocus}
96
+ >
97
+ <div
98
+ ref={setFloatingElement}
99
+ style={floatingStyles}
100
+ className={classnames(styles.menuPopup, classNameOverride)}
101
+ role="dialog"
102
+ aria-modal="true"
103
+ // @ts-expect-error: popover is valid in supported browsers
104
+ popover="manual"
105
+ {...restProps}
106
+ >
107
+ {isLoading && loadingSkeleton ? loadingSkeleton : children}
108
+ </div>
109
+ </FocusOn>
110
+ ) : (
111
+ <></>
112
+ )
113
+ }
114
+
115
+ ResponsiveMenuPopup.displayName = 'FilterMultiSelect.ResponsiveMenuPopup'
@@ -1 +1,2 @@
1
1
  export * from './MenuPopup'
2
+ export * from './ResponsiveMenuPopup'
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var styles = {
4
- "listBox": "ListBox-module_listBox__q95MO",
5
- "overflown": "ListBox-module_overflown__wChQA",
6
- "hidden": "ListBox-module_hidden__eYdXv",
7
- "noResultsWrapper": "ListBox-module_noResultsWrapper__WcLRm"
8
- };
9
- module.exports = styles;
@@ -1,7 +0,0 @@
1
- var styles = {
2
- "listBox": "ListBox-module_listBox__q95MO",
3
- "overflown": "ListBox-module_overflown__wChQA",
4
- "hidden": "ListBox-module_hidden__eYdXv",
5
- "noResultsWrapper": "ListBox-module_noResultsWrapper__WcLRm"
6
- };
7
- export { styles as default };
@@ -1,4 +0,0 @@
1
- var styles = {
2
- "menuPopup": "MenuPopup-module_menuPopup__UVgnP"
3
- };
4
- export { styles as default };
@@ -1,23 +0,0 @@
1
- @import '~@kaizen/design-tokens/sass/spacing';
2
-
3
- .listBox {
4
- list-style: none;
5
- padding: $spacing-sm;
6
- margin: 0 $spacing-sm 0 0;
7
- display: grid;
8
- max-height: 22rem;
9
- overflow-y: auto;
10
- }
11
-
12
- .overflown {
13
- padding-right: $spacing-sm;
14
- }
15
-
16
- .hidden {
17
- display: none;
18
- }
19
-
20
- // this is a div but remove styles briefly flickering to a bullet list as the sections are removed
21
- .noResultsWrapper {
22
- list-style: none;
23
- }
@@ -1,22 +0,0 @@
1
- @import '~@kaizen/design-tokens/sass/spacing';
2
- @import '~@kaizen/design-tokens/sass/shadow';
3
- @import '~@kaizen/design-tokens/sass/border';
4
- @import '~@kaizen/design-tokens/sass/color';
5
-
6
- // figma hard coded: https://www.figma.com/file/eZKEE5kXbEMY3lx84oz8iN/%E2%9D%A4%EF%B8%8F-UI-Kit%3A-Heart?node-id=22814%3A96966
7
- $menu-container-width: 294px;
8
- $menu-container-max-height: 312px;
9
-
10
- .menuPopup {
11
- position: absolute;
12
- z-index: 1000; // from $ca-z-index-dropdown
13
- box-sizing: border-box;
14
- background: $color-white;
15
- color: $color-purple-800;
16
- border-radius: $border-solid-border-radius;
17
- box-shadow: $shadow-large-box-shadow;
18
- padding: $spacing-sm 0;
19
- margin-top: $spacing-xs;
20
- text-align: start;
21
- width: $menu-container-width;
22
- }