@cloudscape-design/components 3.0.930 → 3.0.932
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.
- package/internal/components/option/interfaces.d.ts +1 -1
- package/internal/components/option/interfaces.d.ts.map +1 -1
- package/internal/components/option/interfaces.js.map +1 -1
- package/internal/components/option/utils/prepare-options.d.ts +1 -0
- package/internal/components/option/utils/prepare-options.d.ts.map +1 -1
- package/internal/components/option/utils/prepare-options.js +1 -0
- package/internal/components/option/utils/prepare-options.js.map +1 -1
- package/internal/components/options-list/index.d.ts +1 -0
- package/internal/components/options-list/index.d.ts.map +1 -1
- package/internal/components/options-list/index.js +2 -2
- package/internal/components/options-list/index.js.map +1 -1
- package/internal/components/selectable-item/index.d.ts.map +1 -1
- package/internal/components/selectable-item/index.js +2 -1
- package/internal/components/selectable-item/index.js.map +1 -1
- package/internal/components/selectable-item/interfaces.d.ts +1 -0
- package/internal/components/selectable-item/interfaces.d.ts.map +1 -1
- package/internal/components/selectable-item/interfaces.js.map +1 -1
- package/internal/components/selectable-item/styles.css.js +20 -19
- package/internal/components/selectable-item/styles.scoped.css +41 -37
- package/internal/components/selectable-item/styles.selectors.js +20 -19
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/manifest.json +1 -1
- package/multiselect/interfaces.d.ts +11 -2
- package/multiselect/interfaces.d.ts.map +1 -1
- package/multiselect/interfaces.js.map +1 -1
- package/multiselect/internal.d.ts.map +1 -1
- package/multiselect/internal.js +5 -3
- package/multiselect/internal.js.map +1 -1
- package/multiselect/use-multiselect.d.ts +7 -4
- package/multiselect/use-multiselect.d.ts.map +1 -1
- package/multiselect/use-multiselect.js +33 -9
- package/multiselect/use-multiselect.js.map +1 -1
- package/package.json +1 -1
- package/select/parts/common.d.ts +2 -0
- package/select/parts/common.d.ts.map +1 -0
- package/select/parts/common.js +4 -0
- package/select/parts/common.js.map +1 -0
- package/select/parts/multiselect-item.d.ts.map +1 -1
- package/select/parts/multiselect-item.js +3 -2
- package/select/parts/multiselect-item.js.map +1 -1
- package/select/parts/plain-list.d.ts.map +1 -1
- package/select/parts/plain-list.js +22 -14
- package/select/parts/plain-list.js.map +1 -1
- package/select/parts/virtual-list.d.ts.map +1 -1
- package/select/parts/virtual-list.js +26 -9
- package/select/parts/virtual-list.js.map +1 -1
- package/select/utils/render-options.d.ts +4 -3
- package/select/utils/render-options.d.ts.map +1 -1
- package/select/utils/render-options.js +5 -5
- package/select/utils/render-options.js.map +1 -1
- package/select/utils/scroll-to-index.d.ts +5 -0
- package/select/utils/scroll-to-index.d.ts.map +1 -0
- package/select/utils/scroll-to-index.js +14 -0
- package/select/utils/scroll-to-index.js.map +1 -0
- package/select/utils/use-select.d.ts +4 -1
- package/select/utils/use-select.d.ts.map +1 -1
- package/select/utils/use-select.js +18 -9
- package/select/utils/use-select.js.map +1 -1
- package/table/body-cell/styles.css.js +46 -46
- package/table/body-cell/styles.scoped.css +378 -369
- package/table/body-cell/styles.selectors.js +46 -46
- package/table/internal.d.ts.map +1 -1
- package/table/internal.js +2 -0
- package/table/internal.js.map +1 -1
- package/table/use-prevent-sticky-click-scroll.d.ts +3 -0
- package/table/use-prevent-sticky-click-scroll.d.ts.map +1 -0
- package/table/use-prevent-sticky-click-scroll.js +79 -0
- package/table/use-prevent-sticky-click-scroll.js.map +1 -0
- package/test-utils/dom/internal/dropdown-host.d.ts +20 -2
- package/test-utils/dom/internal/dropdown-host.js +33 -2
- package/test-utils/dom/internal/dropdown-host.js.map +1 -1
- package/test-utils/selectors/internal/dropdown-host.d.ts +1 -0
- package/test-utils/selectors/internal/dropdown-host.js +6 -0
- package/test-utils/selectors/internal/dropdown-host.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-list.js","sourceRoot":"","sources":["../../../../src/select/parts/plain-list.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OA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sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';\n\nimport { useContainerQuery } from '@cloudscape-design/component-toolkit';\n\nimport { DropdownOption } from '../../internal/components/option/interfaces';\nimport OptionsList from '../../internal/components/options-list';\nimport { HighlightType } from '../../internal/components/options-list/utils/use-highlight-option';\nimport { useMergeRefs } from '../../internal/hooks/use-merge-refs';\nimport { renderOptions } from '../utils/render-options';\nimport scrollToIndex from '../utils/scroll-to-index';\nimport { GetOptionProps, MenuProps } from '../utils/use-select';\nimport { fallbackItemHeight } from './common';\n\nimport styles from './styles.css.js';\n\nexport interface SelectListProps {\n menuProps: MenuProps;\n getOptionProps: GetOptionProps;\n filteredOptions: ReadonlyArray<DropdownOption>;\n filteringValue: string;\n highlightType: HighlightType;\n checkboxes?: boolean;\n hasDropdownStatus?: boolean;\n listBottom?: React.ReactNode;\n useInteractiveGroups?: boolean;\n screenReaderContent?: string;\n firstOptionSticky?: boolean;\n}\n\nexport namespace SelectListProps {\n export type SelectListRef = (index: number) => void;\n}\n\nconst PlainList = (\n {\n menuProps,\n getOptionProps,\n filteredOptions,\n filteringValue,\n highlightType,\n checkboxes,\n hasDropdownStatus,\n listBottom,\n useInteractiveGroups,\n screenReaderContent,\n firstOptionSticky,\n }: SelectListProps,\n ref: React.Ref<SelectListProps.SelectListRef>\n) => {\n const stickyOptionRef = useRef<HTMLDivElement>(null);\n const [stickyOptionBlockSize, setStickyOptionBlockSize] = useState(firstOptionSticky ? fallbackItemHeight : 0);\n\n const [width, menuMeasureRef] = useContainerQuery(rect => {\n if (stickyOptionRef.current) {\n // Cannot use container query on the sticky option individually because it is not rendered until the dropdown is open.\n // Not expecting the sticky option to change size without the dropdown also changing size.\n\n // The effects of using the sticky option block size to set the menu scroll padding are covered by integration tests.\n // istanbul ignore next\n setStickyOptionBlockSize(stickyOptionRef.current.clientHeight);\n }\n return { inner: rect.contentBoxWidth, outer: rect.borderBoxWidth };\n });\n\n const menuRef = menuProps.ref;\n\n const mergedRef = useMergeRefs(menuMeasureRef, menuRef);\n\n useImperativeHandle(\n ref,\n () => (index: number) => {\n const isSticky = firstOptionSticky && index === 0;\n if (highlightType.moveFocus && menuRef.current && !isSticky) {\n scrollToIndex({ index, menuEl: menuRef.current });\n }\n },\n [firstOptionSticky, highlightType.moveFocus, menuRef]\n );\n\n const withScrollbar = !!width && width.inner < width.outer;\n\n return (\n <OptionsList {...menuProps} ref={mergedRef} stickyItemBlockSize={stickyOptionBlockSize}>\n {renderOptions({\n options: filteredOptions,\n getOptionProps,\n filteringValue,\n highlightType,\n checkboxes,\n hasDropdownStatus,\n useInteractiveGroups,\n screenReaderContent,\n firstOptionSticky,\n stickyOptionRef,\n withScrollbar,\n })}\n {listBottom ? (\n <li role=\"option\" className={styles['list-bottom']}>\n {listBottom}\n </li>\n ) : null}\n </OptionsList>\n );\n};\n\nexport default forwardRef(PlainList);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-list.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/virtual-list.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA+D,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual-list.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/virtual-list.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA+D,MAAM,OAAO,CAAC;AAUpF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;;AA0H/C,wBAAuC"}
|
|
@@ -6,6 +6,8 @@ import OptionsList from '../../internal/components/options-list';
|
|
|
6
6
|
import { useMergeRefs } from '../../internal/hooks/use-merge-refs';
|
|
7
7
|
import { useVirtual } from '../../internal/hooks/use-virtual';
|
|
8
8
|
import { renderOptions } from '../utils/render-options';
|
|
9
|
+
import customScrollToIndex from '../utils/scroll-to-index';
|
|
10
|
+
import { fallbackItemHeight } from './common';
|
|
9
11
|
import styles from './styles.css.js';
|
|
10
12
|
const VirtualList = (props, ref) => {
|
|
11
13
|
return props.menuProps.open ? React.createElement(VirtualListOpen, Object.assign({}, props, { ref: ref })) : React.createElement(VirtualListClosed, Object.assign({}, props, { ref: ref }));
|
|
@@ -15,6 +17,7 @@ const VirtualListOpen = forwardRef(({ menuProps, getOptionProps, filteredOptions
|
|
|
15
17
|
const [width, menuMeasureRef] = useContainerQuery(rect => ({ inner: rect.contentBoxWidth, outer: rect.borderBoxWidth }), []);
|
|
16
18
|
const menuRefObject = useRef(null);
|
|
17
19
|
const menuRef = useMergeRefs(menuMeasureRef, menuRefObject, menuProps.ref);
|
|
20
|
+
const previousHighlightedIndex = useRef();
|
|
18
21
|
const { virtualItems, totalSize, scrollToIndex } = useVirtual({
|
|
19
22
|
items: filteredOptions,
|
|
20
23
|
parentRef: menuRefObject,
|
|
@@ -23,17 +26,32 @@ const VirtualListOpen = forwardRef(({ menuProps, getOptionProps, filteredOptions
|
|
|
23
26
|
// 1: because the component got resized (width property got updated)
|
|
24
27
|
// 2: because the option changed its content (filteringValue property controls the highlight and the visibility of hidden tags)
|
|
25
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
-
estimateSize: useCallback(() =>
|
|
29
|
+
estimateSize: useCallback(() => fallbackItemHeight, [width === null || width === void 0 ? void 0 : width.inner, filteringValue]),
|
|
27
30
|
firstItemSticky: firstOptionSticky,
|
|
28
31
|
});
|
|
29
32
|
useImperativeHandle(ref, () => (index) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
if (highlightType.moveFocus) {
|
|
34
|
+
const movingUp = previousHighlightedIndex.current !== undefined && index < previousHighlightedIndex.current;
|
|
35
|
+
if (firstOptionSticky && movingUp && index !== 0 && menuRefObject.current) {
|
|
36
|
+
// React-Virtual v2 does not offer a proper way to handle sticky elements when scrolling,
|
|
37
|
+
// so until we upgrade to v3, use our own scroll implementation
|
|
38
|
+
// to prevent newly highlighted element from being covered by the sticky element
|
|
39
|
+
// when moving the highlight upwards in the list.
|
|
40
|
+
// Scrolling behavior is covered by integration tests.
|
|
41
|
+
// istanbul ignore next
|
|
42
|
+
customScrollToIndex({
|
|
43
|
+
index,
|
|
44
|
+
menuEl: menuRefObject === null || menuRefObject === void 0 ? void 0 : menuRefObject.current,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
scrollToIndex(index);
|
|
49
|
+
}
|
|
33
50
|
}
|
|
34
|
-
|
|
51
|
+
previousHighlightedIndex.current = index;
|
|
52
|
+
}, [firstOptionSticky, highlightType.moveFocus, scrollToIndex]);
|
|
35
53
|
const stickySize = firstOptionSticky ? virtualItems[0].size : 0;
|
|
36
|
-
const
|
|
54
|
+
const withScrollbar = !!width && width.inner < width.outer;
|
|
37
55
|
const finalOptions = renderOptions({
|
|
38
56
|
options: virtualItems.map(({ index }) => filteredOptions[index]),
|
|
39
57
|
getOptionProps,
|
|
@@ -44,11 +62,10 @@ const VirtualListOpen = forwardRef(({ menuProps, getOptionProps, filteredOptions
|
|
|
44
62
|
virtualItems,
|
|
45
63
|
useInteractiveGroups,
|
|
46
64
|
screenReaderContent,
|
|
47
|
-
ariaSetsize: filteredOptions.length,
|
|
48
|
-
withScrollbar: hasScrollbar,
|
|
49
65
|
firstOptionSticky,
|
|
66
|
+
withScrollbar,
|
|
50
67
|
});
|
|
51
|
-
return (React.createElement(OptionsList, Object.assign({}, menuProps, { ref: menuRef }),
|
|
68
|
+
return (React.createElement(OptionsList, Object.assign({}, menuProps, { stickyItemBlockSize: stickySize, ref: menuRef }),
|
|
52
69
|
finalOptions,
|
|
53
70
|
React.createElement("div", { "aria-hidden": "true", key: "total-size", className: styles['layout-strut'], style: { height: totalSize - stickySize } }),
|
|
54
71
|
listBottom ? (React.createElement("li", { role: "option", className: styles['list-bottom'] }, listBottom)) : null));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-list.js","sourceRoot":"","sources":["../../../../src/select/parts/virtual-list.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,WAAW,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual-list.js","sourceRoot":"","sources":["../../../../src/select/parts/virtual-list.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,WAAW,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,WAAW,GAAG,CAAC,KAAsB,EAAE,GAA6C,EAAE,EAAE;IAC5F,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAC,eAAe,oBAAK,KAAK,IAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,oBAAC,iBAAiB,oBAAK,KAA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E,MAAM,EAAE,SAAS,GAAG,UAAU,EAAE,GACzC;QACD,UAAU,CAAC,CAAC,CAAC,CACZ,4BAAI,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,IAC/C,UAAU,CACR,CACN,CAAC,CAAC,CAAC,IAAI,CACI,CACf,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,iBAAiB,GAAG,UAAU,CAClC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAmB,EAAE,GAA6C,EAAE,EAAE;IAC5F,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,CACL,oBAAC,WAAW,oBAAK,SAAS,IAAE,GAAG,EAAE,SAAS,CAAC,GAAG,KAC3C,UAAU,CAAC,CAAC,CAAC,CACZ,4BAAI,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAE,MAAM,CAAC,aAAa,CAAC,IAC/C,UAAU,CACR,CACN,CAAC,CAAC,CAAC,IAAI,CACI,CACf,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC,WAAW,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';\n\nimport { useContainerQuery } from '@cloudscape-design/component-toolkit';\n\nimport OptionsList from '../../internal/components/options-list';\nimport { useMergeRefs } from '../../internal/hooks/use-merge-refs';\nimport { useVirtual } from '../../internal/hooks/use-virtual';\nimport { renderOptions } from '../utils/render-options';\nimport customScrollToIndex from '../utils/scroll-to-index';\nimport { fallbackItemHeight } from './common';\nimport { SelectListProps } from './plain-list';\n\nimport styles from './styles.css.js';\n\nconst VirtualList = (props: SelectListProps, ref: React.Ref<SelectListProps.SelectListRef>) => {\n return props.menuProps.open ? <VirtualListOpen {...props} ref={ref} /> : <VirtualListClosed {...props} ref={ref} />;\n};\n\nconst VirtualListOpen = forwardRef(\n (\n {\n menuProps,\n getOptionProps,\n filteredOptions,\n filteringValue,\n highlightType,\n checkboxes,\n hasDropdownStatus,\n listBottom,\n useInteractiveGroups,\n screenReaderContent,\n firstOptionSticky,\n }: SelectListProps,\n ref: React.Ref<SelectListProps.SelectListRef>\n ) => {\n // update component, when it gets wider or narrower to reposition items\n const [width, menuMeasureRef] = useContainerQuery(\n rect => ({ inner: rect.contentBoxWidth, outer: rect.borderBoxWidth }),\n []\n );\n const menuRefObject = useRef(null);\n const menuRef = useMergeRefs(menuMeasureRef, menuRefObject, menuProps.ref);\n const previousHighlightedIndex = useRef<number>();\n const { virtualItems, totalSize, scrollToIndex } = useVirtual({\n items: filteredOptions,\n parentRef: menuRefObject,\n // estimateSize is a dependency of measurements memo. We update it to force full recalculation\n // when the height of any option could have changed:\n // 1: because the component got resized (width property got updated)\n // 2: because the option changed its content (filteringValue property controls the highlight and the visibility of hidden tags)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n estimateSize: useCallback(() => fallbackItemHeight, [width?.inner, filteringValue]),\n firstItemSticky: firstOptionSticky,\n });\n\n useImperativeHandle(\n ref,\n () => (index: number) => {\n if (highlightType.moveFocus) {\n const movingUp = previousHighlightedIndex.current !== undefined && index < previousHighlightedIndex.current;\n if (firstOptionSticky && movingUp && index !== 0 && menuRefObject.current) {\n // React-Virtual v2 does not offer a proper way to handle sticky elements when scrolling,\n // so until we upgrade to v3, use our own scroll implementation\n // to prevent newly highlighted element from being covered by the sticky element\n // when moving the highlight upwards in the list.\n\n // Scrolling behavior is covered by integration tests.\n // istanbul ignore next\n customScrollToIndex({\n index,\n menuEl: menuRefObject?.current,\n });\n } else {\n scrollToIndex(index);\n }\n }\n previousHighlightedIndex.current = index;\n },\n [firstOptionSticky, highlightType.moveFocus, scrollToIndex]\n );\n\n const stickySize = firstOptionSticky ? virtualItems[0].size : 0;\n const withScrollbar = !!width && width.inner < width.outer;\n\n const finalOptions = renderOptions({\n options: virtualItems.map(({ index }) => filteredOptions[index]),\n getOptionProps,\n filteringValue,\n highlightType,\n checkboxes,\n hasDropdownStatus,\n virtualItems,\n useInteractiveGroups,\n screenReaderContent,\n firstOptionSticky,\n withScrollbar,\n });\n\n return (\n <OptionsList {...menuProps} stickyItemBlockSize={stickySize} ref={menuRef}>\n {finalOptions}\n <div\n aria-hidden=\"true\"\n key=\"total-size\"\n className={styles['layout-strut']}\n style={{ height: totalSize - stickySize }}\n />\n {listBottom ? (\n <li role=\"option\" className={styles['list-bottom']}>\n {listBottom}\n </li>\n ) : null}\n </OptionsList>\n );\n }\n);\n\nconst VirtualListClosed = forwardRef(\n ({ menuProps, listBottom }: SelectListProps, ref: React.Ref<SelectListProps.SelectListRef>) => {\n useImperativeHandle(ref, () => () => {}, []);\n return (\n <OptionsList {...menuProps} ref={menuProps.ref}>\n {listBottom ? (\n <li role=\"option\" className={styles['list-bottom']}>\n {listBottom}\n </li>\n ) : null}\n </OptionsList>\n );\n }\n);\n\nexport default forwardRef(VirtualList);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { DropdownOption } from '../../internal/components/option/interfaces';
|
|
3
3
|
import { HighlightType } from '../../internal/components/options-list/utils/use-highlight-option';
|
|
4
4
|
import { VirtualItem } from '../../internal/vendor/react-virtual';
|
|
@@ -13,9 +13,10 @@ interface RenderOptionProps {
|
|
|
13
13
|
useInteractiveGroups?: boolean;
|
|
14
14
|
screenReaderContent?: string;
|
|
15
15
|
ariaSetsize?: number;
|
|
16
|
-
withScrollbar
|
|
16
|
+
withScrollbar: boolean;
|
|
17
17
|
firstOptionSticky?: boolean;
|
|
18
|
+
stickyOptionRef?: React.Ref<HTMLDivElement>;
|
|
18
19
|
}
|
|
19
|
-
export declare const renderOptions: ({ options, getOptionProps, filteringValue, highlightType, checkboxes, hasDropdownStatus, virtualItems, useInteractiveGroups, screenReaderContent, ariaSetsize, withScrollbar, firstOptionSticky, }: RenderOptionProps) => JSX.Element[];
|
|
20
|
+
export declare const renderOptions: ({ options, getOptionProps, filteringValue, highlightType, checkboxes, hasDropdownStatus, virtualItems, useInteractiveGroups, screenReaderContent, ariaSetsize, withScrollbar, firstOptionSticky, stickyOptionRef, }: RenderOptionProps) => JSX.Element[];
|
|
20
21
|
export {};
|
|
21
22
|
//# sourceMappingURL=render-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-options.d.ts","sourceRoot":"","sources":["../../../../src/select/utils/render-options.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"render-options.d.ts","sourceRoot":"","sources":["../../../../src/select/utils/render-options.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,mEAAmE,CAAC;AAClG,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAKlE,UAAU,iBAAiB;IACzB,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,cAAc,EAAE,GAAG,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,aAAa,wNAcvB,iBAAiB,kBAiCnB,CAAC"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import Item from '../parts/item';
|
|
5
|
-
import
|
|
5
|
+
import MultiselectItem from '../parts/multiselect-item';
|
|
6
6
|
import { getItemProps } from './get-item-props';
|
|
7
|
-
export const renderOptions = ({ options, getOptionProps, filteringValue, highlightType, checkboxes = false, hasDropdownStatus, virtualItems, useInteractiveGroups, screenReaderContent, ariaSetsize, withScrollbar, firstOptionSticky, }) => {
|
|
7
|
+
export const renderOptions = ({ options, getOptionProps, filteringValue, highlightType, checkboxes = false, hasDropdownStatus, virtualItems, useInteractiveGroups, screenReaderContent, ariaSetsize, withScrollbar, firstOptionSticky, stickyOptionRef, }) => {
|
|
8
8
|
return options.map((option, index) => {
|
|
9
9
|
const virtualItem = virtualItems && virtualItems[index];
|
|
10
10
|
const globalIndex = virtualItem ? virtualItem.index : index;
|
|
@@ -12,14 +12,14 @@ export const renderOptions = ({ options, getOptionProps, filteringValue, highlig
|
|
|
12
12
|
option,
|
|
13
13
|
index: globalIndex,
|
|
14
14
|
getOptionProps,
|
|
15
|
-
filteringValue,
|
|
15
|
+
filteringValue: option.type === 'select-all' ? '' : filteringValue,
|
|
16
16
|
checkboxes,
|
|
17
17
|
});
|
|
18
18
|
const isLastItem = index === options.length - 1;
|
|
19
19
|
const padBottom = !hasDropdownStatus && isLastItem;
|
|
20
|
-
const ListItem = useInteractiveGroups ?
|
|
20
|
+
const ListItem = useInteractiveGroups ? MultiselectItem : Item;
|
|
21
21
|
const isSticky = firstOptionSticky && globalIndex === 0;
|
|
22
|
-
return (React.createElement(ListItem, Object.assign({ key: globalIndex }, props, { virtualPosition:
|
|
22
|
+
return (React.createElement(ListItem, Object.assign({ key: globalIndex }, props, { virtualPosition: virtualItem && virtualItem.start, ref: isSticky && stickyOptionRef ? stickyOptionRef : virtualItem && virtualItem.measureRef, padBottom: padBottom, screenReaderContent: screenReaderContent, ariaPosinset: globalIndex + 1, ariaSetsize: ariaSetsize, highlightType: highlightType.type, withScrollbar: withScrollbar, sticky: isSticky })));
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
//# sourceMappingURL=render-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-options.js","sourceRoot":"","sources":["../../../../src/select/utils/render-options.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,IAAI,MAAM,eAAe,CAAC;AACjC,OAAO,eAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"render-options.js","sourceRoot":"","sources":["../../../../src/select/utils/render-options.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,IAAI,MAAM,eAAe,CAAC;AACjC,OAAO,eAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAkBhD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAC5B,OAAO,EACP,cAAc,EACd,cAAc,EACd,aAAa,EACb,UAAU,GAAG,KAAK,EAClB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,eAAe,GACG,EAAE,EAAE;IACtB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACnC,MAAM,WAAW,GAAG,YAAY,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5D,MAAM,KAAK,GAAG,YAAY,CAAC;YACzB,MAAM;YACN,KAAK,EAAE,WAAW;YAClB,cAAc;YACd,cAAc,EAAE,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc;YAClE,UAAU;SACX,CAAC,CAAC;QAEH,MAAM,UAAU,GAAG,KAAK,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QAChD,MAAM,SAAS,GAAG,CAAC,iBAAiB,IAAI,UAAU,CAAC;QACnD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,MAAM,QAAQ,GAAG,iBAAiB,IAAI,WAAW,KAAK,CAAC,CAAC;QAExD,OAAO,CACL,oBAAC,QAAQ,kBACP,GAAG,EAAE,WAAW,IACZ,KAAK,IACT,eAAe,EAAE,WAAW,IAAI,WAAW,CAAC,KAAK,EACjD,GAAG,EAAE,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,UAAU,EAC1F,SAAS,EAAE,SAAS,EACpB,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,WAAW,GAAG,CAAC,EAC7B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,CAAC,IAAI,EACjC,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,QAAQ,IAChB,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { DropdownOption } from '../../internal/components/option/interfaces';\nimport { HighlightType } from '../../internal/components/options-list/utils/use-highlight-option';\nimport { VirtualItem } from '../../internal/vendor/react-virtual';\nimport Item from '../parts/item';\nimport MultiselectItem from '../parts/multiselect-item';\nimport { getItemProps } from './get-item-props';\n\ninterface RenderOptionProps {\n options: ReadonlyArray<DropdownOption>;\n getOptionProps: any;\n filteringValue: string;\n highlightType: HighlightType;\n checkboxes?: boolean;\n hasDropdownStatus?: boolean;\n virtualItems?: VirtualItem[];\n useInteractiveGroups?: boolean;\n screenReaderContent?: string;\n ariaSetsize?: number;\n withScrollbar: boolean;\n firstOptionSticky?: boolean;\n stickyOptionRef?: React.Ref<HTMLDivElement>;\n}\n\nexport const renderOptions = ({\n options,\n getOptionProps,\n filteringValue,\n highlightType,\n checkboxes = false,\n hasDropdownStatus,\n virtualItems,\n useInteractiveGroups,\n screenReaderContent,\n ariaSetsize,\n withScrollbar,\n firstOptionSticky,\n stickyOptionRef,\n}: RenderOptionProps) => {\n return options.map((option, index) => {\n const virtualItem = virtualItems && virtualItems[index];\n const globalIndex = virtualItem ? virtualItem.index : index;\n const props = getItemProps({\n option,\n index: globalIndex,\n getOptionProps,\n filteringValue: option.type === 'select-all' ? '' : filteringValue,\n checkboxes,\n });\n\n const isLastItem = index === options.length - 1;\n const padBottom = !hasDropdownStatus && isLastItem;\n const ListItem = useInteractiveGroups ? MultiselectItem : Item;\n const isSticky = firstOptionSticky && globalIndex === 0;\n\n return (\n <ListItem\n key={globalIndex}\n {...props}\n virtualPosition={virtualItem && virtualItem.start}\n ref={isSticky && stickyOptionRef ? stickyOptionRef : virtualItem && virtualItem.measureRef}\n padBottom={padBottom}\n screenReaderContent={screenReaderContent}\n ariaPosinset={globalIndex + 1}\n ariaSetsize={ariaSetsize}\n highlightType={highlightType.type}\n withScrollbar={withScrollbar}\n sticky={isSticky}\n />\n );\n });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-to-index.d.ts","sourceRoot":"","sources":["../../../../src/select/utils/scroll-to-index.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,QAUjF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { scrollElementIntoView } from '../../internal/utils/scrollable-containers';
|
|
4
|
+
export default function ({ index, menuEl }) {
|
|
5
|
+
const item = menuEl.querySelector(`[data-mouse-target="${index}"]`);
|
|
6
|
+
if (item) {
|
|
7
|
+
// In edge case dropdown can be very small, scrolling can cause side effect AWSUI-60318
|
|
8
|
+
if (menuEl.clientHeight !== undefined && menuEl.clientHeight > 15) {
|
|
9
|
+
/* istanbul ignore next: clientHeight always returns 0 in JSDOM, the line is covered by integ tests */
|
|
10
|
+
scrollElementIntoView(item);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=scroll-to-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-to-index.js","sourceRoot":"","sources":["../../../../src/select/utils/scroll-to-index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAEnF,MAAM,CAAC,OAAO,WAAW,EAAE,KAAK,EAAE,MAAM,EAA0C;IAChF,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,CAAc,uBAAuB,KAAK,IAAI,CAAC,CAAC;IAEjF,IAAI,IAAI,EAAE;QACR,uFAAuF;QACvF,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,YAAY,GAAG,EAAE,EAAE;YACjE,sGAAsG;YACtG,qBAAqB,CAAC,IAAI,CAAC,CAAC;SAC7B;KACF;AACH,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { scrollElementIntoView } from '../../internal/utils/scrollable-containers';\n\nexport default function ({ index, menuEl }: { index: number; menuEl: HTMLElement }) {\n const item = menuEl.querySelector<HTMLElement>(`[data-mouse-target=\"${index}\"]`);\n\n if (item) {\n // In edge case dropdown can be very small, scrolling can cause side effect AWSUI-60318\n if (menuEl.clientHeight !== undefined && menuEl.clientHeight > 15) {\n /* istanbul ignore next: clientHeight always returns 0 in JSDOM, the line is covered by integ tests */\n scrollElementIntoView(item);\n }\n }\n}\n"]}
|
|
@@ -25,11 +25,14 @@ interface UseSelectProps {
|
|
|
25
25
|
setFilteringValue?: (filteringText: string) => void;
|
|
26
26
|
useInteractiveGroups?: boolean;
|
|
27
27
|
statusType: DropdownStatusProps.StatusType;
|
|
28
|
+
isAllSelected?: boolean;
|
|
29
|
+
isSomeSelected?: boolean;
|
|
30
|
+
toggleAll?: () => void;
|
|
28
31
|
}
|
|
29
32
|
export interface SelectTriggerProps extends ButtonTriggerProps {
|
|
30
33
|
ref: RefObject<HTMLButtonElement>;
|
|
31
34
|
}
|
|
32
|
-
export declare function useSelect({ selectedOptions, updateSelectedOption, options, filteringType, onBlur, onFocus, externalRef, keepOpen, embedded, fireLoadItems, setFilteringValue, useInteractiveGroups, statusType, }: UseSelectProps): {
|
|
35
|
+
export declare function useSelect({ selectedOptions, updateSelectedOption, options, filteringType, onBlur, onFocus, externalRef, keepOpen, embedded, fireLoadItems, setFilteringValue, useInteractiveGroups, statusType, isAllSelected, isSomeSelected, toggleAll, }: UseSelectProps): {
|
|
33
36
|
isOpen: boolean;
|
|
34
37
|
highlightedOption: DropdownOption | undefined;
|
|
35
38
|
highlightedIndex: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-select.d.ts","sourceRoot":"","sources":["../../../../src/select/utils/use-select.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,+C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AAG,CAAC,CAAC;IAC5B,aAAa,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,iBAAiB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,GAAG,EAAE,SAAS,CAAC,iBAAiB,CAAC,CAAC;CACnC;AAED,wBAAgB,SAAS,CAAC,EACxB,eAAe,EACf,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,oBAA4B,EAC5B,UAAU,EACV,aAAa,EACb,cAAc,EACd,SAAS,GACV,EAAE,cAAc;;;;;;4BA4Ge,KAC5B,aAAa,EACb,SAAS,GAAG,QAAQ,GAAG,mBAAmB,GAAG,qBAAqB,CACnE;;0BA4B0B,QAAQ,WAAW,CAAC;6BAoEf,cAAc,SAAS,MAAM;;4BApJ9B,cAAc;;;EAiO9C"}
|
|
@@ -9,7 +9,7 @@ import useForwardFocus from '../../internal/hooks/forward-focus';
|
|
|
9
9
|
import { usePrevious } from '../../internal/hooks/use-previous';
|
|
10
10
|
import { useUniqueId } from '../../internal/hooks/use-unique-id';
|
|
11
11
|
import { connectOptionsByValue } from './connect-options';
|
|
12
|
-
export function useSelect({ selectedOptions, updateSelectedOption, options, filteringType, onBlur, onFocus, externalRef, keepOpen, embedded, fireLoadItems, setFilteringValue, useInteractiveGroups = false, statusType, }) {
|
|
12
|
+
export function useSelect({ selectedOptions, updateSelectedOption, options, filteringType, onBlur, onFocus, externalRef, keepOpen, embedded, fireLoadItems, setFilteringValue, useInteractiveGroups = false, statusType, isAllSelected, isSomeSelected, toggleAll, }) {
|
|
13
13
|
const interactivityCheck = useInteractiveGroups ? isGroupInteractive : isInteractive;
|
|
14
14
|
const isHighlightable = (option) => !!option && (useInteractiveGroups || option.type !== 'parent');
|
|
15
15
|
const filterRef = useRef(null);
|
|
@@ -24,7 +24,7 @@ export function useSelect({ selectedOptions, updateSelectedOption, options, filt
|
|
|
24
24
|
}
|
|
25
25
|
return selectedValuesSet;
|
|
26
26
|
}, new Set());
|
|
27
|
-
const [{ highlightType, highlightedOption, highlightedIndex }, { moveHighlightWithKeyboard, resetHighlightWithKeyboard, setHighlightedIndexWithMouse, highlightOptionWithKeyboard, goHomeWithKeyboard, goEndWithKeyboard, },] = useHighlightedOption({ options, isHighlightable });
|
|
27
|
+
const [{ highlightType, highlightedOption, highlightedIndex }, { moveHighlightWithKeyboard, resetHighlightWithKeyboard, setHighlightedIndexWithMouse, highlightOptionWithKeyboard, goHomeWithKeyboard, goEndWithKeyboard, },] = useHighlightedOption({ options: options, isHighlightable });
|
|
28
28
|
const { isOpen, openDropdown, closeDropdown, toggleDropdown, openedWithKeyboard } = useOpenState({
|
|
29
29
|
defaultOpen: embedded,
|
|
30
30
|
onOpen: () => fireLoadItems(''),
|
|
@@ -44,17 +44,25 @@ export function useSelect({ selectedOptions, updateSelectedOption, options, filt
|
|
|
44
44
|
const menuId = useUniqueId('option-list');
|
|
45
45
|
const dialogId = useUniqueId('dialog');
|
|
46
46
|
const highlightedOptionId = getOptionId(menuId, highlightedIndex);
|
|
47
|
-
const
|
|
47
|
+
const closeDropdownIfNecessary = () => {
|
|
48
48
|
var _a;
|
|
49
|
+
if (!keepOpen) {
|
|
50
|
+
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
51
|
+
closeDropdown();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const selectOption = (option) => {
|
|
49
55
|
const optionToSelect = option || highlightedOption;
|
|
50
56
|
if (!optionToSelect || !interactivityCheck(optionToSelect)) {
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
if (optionToSelect.type === 'select-all' && toggleAll) {
|
|
60
|
+
toggleAll();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
updateSelectedOption(optionToSelect.option);
|
|
57
64
|
}
|
|
65
|
+
closeDropdownIfNecessary();
|
|
58
66
|
};
|
|
59
67
|
const activeKeyDownHandler = useMenuKeyboard({
|
|
60
68
|
goUp: () => {
|
|
@@ -182,9 +190,10 @@ export function useSelect({ selectedOptions, updateSelectedOption, options, filt
|
|
|
182
190
|
};
|
|
183
191
|
const getOptionProps = (option, index) => {
|
|
184
192
|
var _a;
|
|
193
|
+
const isSelectAll = option.type === 'select-all';
|
|
185
194
|
const highlighted = option === highlightedOption;
|
|
186
195
|
const groupState = isGroup(option.option) ? getGroupState(option.option) : undefined;
|
|
187
|
-
const selected = __selectedOptions.indexOf(option) > -1 || !!(groupState === null || groupState === void 0 ? void 0 : groupState.selected);
|
|
196
|
+
const selected = isSelectAll ? isAllSelected : __selectedOptions.indexOf(option) > -1 || !!(groupState === null || groupState === void 0 ? void 0 : groupState.selected);
|
|
188
197
|
const nextOption = (_a = options[index + 1]) === null || _a === void 0 ? void 0 : _a.option;
|
|
189
198
|
const isNextSelected = !!nextOption && isGroup(nextOption)
|
|
190
199
|
? getGroupState(nextOption).selected
|
|
@@ -195,7 +204,7 @@ export function useSelect({ selectedOptions, updateSelectedOption, options, filt
|
|
|
195
204
|
highlighted,
|
|
196
205
|
selected,
|
|
197
206
|
isNextSelected,
|
|
198
|
-
indeterminate: !!(groupState === null || groupState === void 0 ? void 0 : groupState.indeterminate),
|
|
207
|
+
indeterminate: !!(groupState === null || groupState === void 0 ? void 0 : groupState.indeterminate) || (isSelectAll && !isAllSelected && isSomeSelected),
|
|
199
208
|
['data-mouse-target']: isHighlightable(option) ? index : -1,
|
|
200
209
|
id: getOptionId(menuId, index),
|
|
201
210
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-select.js","sourceRoot":"","sources":["../../../../src/select/utils/use-select.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAM1C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAEnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mEAAmE,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AAChH,OAAO,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAA6B,MAAM,uBAAuB,CAAC;AAC1F,OAAO,eAAe,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAGjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAyB1D,MAAM,UAAU,SAAS,CAAC,EACxB,eAAe,EACf,oBAAoB,EACpB,OAAO,EACP,aAAa,EACb,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,oBAAoB,GAAG,KAAK,EAC5B,UAAU,GACK;IACf,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa,CAAC;IAErF,MAAM,eAAe,GAAG,CAAC,MAAuB,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,oBAAoB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;IAEpH,MAAM,SAAS,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rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { RefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nimport { ButtonTriggerProps } from '../../internal/components/button-trigger';\nimport { DropdownProps } from '../../internal/components/dropdown/interfaces';\nimport { DropdownStatusProps } from '../../internal/components/dropdown-status';\nimport { DropdownOption, OptionDefinition, OptionGroup } from '../../internal/components/option/interfaces';\nimport { isGroup, isGroupInteractive, isInteractive } from '../../internal/components/option/utils/filter-options';\nimport { OptionsListProps } from '../../internal/components/options-list';\nimport { useHighlightedOption } from '../../internal/components/options-list/utils/use-highlight-option';\nimport { getOptionId } from '../../internal/components/options-list/utils/use-ids';\nimport { useMenuKeyboard, useTriggerKeyboard } from '../../internal/components/options-list/utils/use-keyboard';\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../../internal/events';\nimport useForwardFocus from '../../internal/hooks/forward-focus';\nimport { usePrevious } from '../../internal/hooks/use-previous';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport { FilterProps } from '../parts/filter';\nimport { ItemProps } from '../parts/item';\nimport { connectOptionsByValue } from './connect-options';\n\nexport type MenuProps = Omit<OptionsListProps, 'children'> & { ref: React.RefObject<HTMLUListElement> };\nexport type GetOptionProps = (option: DropdownOption, index: number) => ItemProps;\n\ninterface UseSelectProps {\n selectedOptions: ReadonlyArray<OptionDefinition>;\n updateSelectedOption: (option: OptionDefinition) => void;\n options: ReadonlyArray<DropdownOption>;\n filteringType: string;\n keepOpen?: boolean;\n embedded?: boolean;\n onBlur?: NonCancelableEventHandler;\n onFocus?: NonCancelableEventHandler;\n externalRef: React.Ref<any>;\n fireLoadItems: (filteringText: string) => void;\n setFilteringValue?: (filteringText: string) => void;\n useInteractiveGroups?: boolean;\n statusType: DropdownStatusProps.StatusType;\n}\n\nexport interface SelectTriggerProps extends ButtonTriggerProps {\n ref: RefObject<HTMLButtonElement>;\n}\n\nexport function useSelect({\n selectedOptions,\n updateSelectedOption,\n options,\n filteringType,\n onBlur,\n onFocus,\n externalRef,\n keepOpen,\n embedded,\n fireLoadItems,\n setFilteringValue,\n useInteractiveGroups = false,\n statusType,\n}: UseSelectProps) {\n const interactivityCheck = useInteractiveGroups ? isGroupInteractive : isInteractive;\n\n const isHighlightable = (option?: DropdownOption) => !!option && (useInteractiveGroups || option.type !== 'parent');\n\n const filterRef = useRef<HTMLInputElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const menuRef = useRef<HTMLUListElement>(null);\n const hasFilter = filteringType !== 'none' && !embedded;\n const activeRef = hasFilter ? filterRef : menuRef;\n const __selectedOptions = connectOptionsByValue(options, selectedOptions);\n const __selectedValuesSet = selectedOptions.reduce((selectedValuesSet: Set<string>, item: OptionDefinition) => {\n if (item.value) {\n selectedValuesSet.add(item.value);\n }\n return selectedValuesSet;\n }, new Set<string>());\n const [\n { highlightType, highlightedOption, highlightedIndex },\n {\n moveHighlightWithKeyboard,\n resetHighlightWithKeyboard,\n setHighlightedIndexWithMouse,\n highlightOptionWithKeyboard,\n goHomeWithKeyboard,\n goEndWithKeyboard,\n },\n ] = useHighlightedOption({ options, isHighlightable });\n\n const { isOpen, openDropdown, closeDropdown, toggleDropdown, openedWithKeyboard } = useOpenState({\n defaultOpen: embedded,\n onOpen: () => fireLoadItems(''),\n onClose: () => {\n resetHighlightWithKeyboard();\n setFilteringValue?.('');\n },\n });\n\n const handleFocus = () => {\n fireNonCancelableEvent(onFocus, {});\n };\n\n const handleBlur = () => {\n fireNonCancelableEvent(onBlur, {});\n closeDropdown();\n };\n\n const hasSelectedOption = __selectedOptions.length > 0;\n const menuId = useUniqueId('option-list');\n const dialogId = useUniqueId('dialog');\n const highlightedOptionId = getOptionId(menuId, highlightedIndex);\n\n const selectOption = (option?: DropdownOption) => {\n const optionToSelect = option || highlightedOption;\n if (!optionToSelect || !interactivityCheck(optionToSelect)) {\n return;\n }\n updateSelectedOption(optionToSelect.option);\n if (!keepOpen) {\n triggerRef.current?.focus();\n closeDropdown();\n }\n };\n\n const activeKeyDownHandler = useMenuKeyboard({\n goUp: () => {\n if (\n (!useInteractiveGroups && highlightedOption?.type === 'child' && highlightedIndex === 1) ||\n highlightedIndex === 0\n ) {\n goEndWithKeyboard();\n return;\n }\n\n moveHighlightWithKeyboard(-1);\n },\n goDown: () => {\n if (highlightedIndex === options.length - 1) {\n goHomeWithKeyboard();\n return;\n }\n\n moveHighlightWithKeyboard(1);\n },\n selectOption,\n goHome: goHomeWithKeyboard,\n goEnd: goEndWithKeyboard,\n closeDropdown: () => {\n if (!embedded) {\n triggerRef.current?.focus();\n closeDropdown();\n }\n },\n preventNativeSpace: !hasFilter || !!highlightedOption,\n });\n\n const triggerKeyDownHandler = useTriggerKeyboard({\n openDropdown: () => openDropdown(true),\n goHome: goHomeWithKeyboard,\n });\n\n const getDropdownProps: () => Pick<\n DropdownProps,\n 'onFocus' | 'onBlur' | 'dropdownContentId' | 'dropdownContentRole'\n > = () => ({\n onFocus: handleFocus,\n onBlur: handleBlur,\n dropdownContentId: dialogId,\n dropdownContentRole: hasFilter ? 'dialog' : undefined,\n });\n\n const getTriggerProps = (disabled = false, autoFocus = false) => {\n const triggerProps: SelectTriggerProps = {\n ref: triggerRef,\n onFocus: () => closeDropdown(),\n autoFocus,\n ariaHasPopup: hasFilter ? 'dialog' : 'listbox',\n ariaControls: isOpen ? (hasFilter ? dialogId : menuId) : undefined,\n };\n if (!disabled) {\n triggerProps.onMouseDown = (event: CustomEvent) => {\n event.preventDefault(); // prevent current focus from blurring as it immediately closes the dropdown\n if (isOpen) {\n triggerRef.current?.focus();\n }\n toggleDropdown();\n };\n triggerProps.onKeyDown = triggerKeyDownHandler;\n }\n return triggerProps;\n };\n\n const getFilterProps = (): Partial<FilterProps> => {\n if (!hasFilter || !setFilteringValue) {\n return {};\n }\n\n return {\n ref: filterRef,\n onKeyDown: activeKeyDownHandler,\n onChange: event => {\n setFilteringValue(event.detail.value);\n resetHighlightWithKeyboard();\n },\n __onDelayedInput: event => {\n fireLoadItems(event.detail.value);\n },\n __nativeAttributes: {\n 'aria-activedescendant': highlightedOptionId,\n ['aria-owns']: menuId,\n ['aria-controls']: menuId,\n },\n };\n };\n\n const getMenuProps = () => {\n const menuProps: MenuProps = {\n id: menuId,\n ref: menuRef,\n open: isOpen,\n onMouseUp: itemIndex => {\n if (itemIndex > -1) {\n selectOption(options[itemIndex]);\n }\n },\n onMouseMove: itemIndex => {\n if (itemIndex > -1) {\n setHighlightedIndexWithMouse(itemIndex);\n }\n },\n statusType,\n };\n if (!hasFilter) {\n menuProps.onKeyDown = activeKeyDownHandler;\n menuProps.nativeAttributes = {\n 'aria-activedescendant': highlightedOptionId,\n };\n }\n if (embedded) {\n menuProps.onFocus = () => {\n if (!highlightedOption) {\n goHomeWithKeyboard();\n }\n };\n menuProps.onBlur = () => {\n resetHighlightWithKeyboard();\n };\n }\n return menuProps;\n };\n const getGroupState = (option: OptionGroup) => {\n const totalSelected = option.options.filter(item => !!item.value && __selectedValuesSet.has(item.value)).length;\n const hasSelected = totalSelected > 0;\n const allSelected = totalSelected === option.options.length;\n return {\n selected: hasSelected && allSelected && useInteractiveGroups,\n indeterminate: hasSelected && !allSelected,\n };\n };\n\n const getOptionProps = (option: DropdownOption, index: number) => {\n const highlighted = option === highlightedOption;\n const groupState = isGroup(option.option) ? getGroupState(option.option) : undefined;\n const selected = __selectedOptions.indexOf(option) > -1 || !!groupState?.selected;\n const nextOption = options[index + 1]?.option;\n const isNextSelected =\n !!nextOption && isGroup(nextOption)\n ? getGroupState(nextOption).selected\n : __selectedOptions.indexOf(options[index + 1]) > -1;\n const optionProps: any = {\n key: index,\n option,\n highlighted,\n selected,\n isNextSelected,\n indeterminate: !!groupState?.indeterminate,\n ['data-mouse-target']: isHighlightable(option) ? index : -1,\n id: getOptionId(menuId, index),\n };\n\n return optionProps;\n };\n\n const prevOpen = usePrevious<boolean>(isOpen);\n useEffect(() => {\n // highlight the first selected option, when opening the Select component without filter input\n // keep the focus in the filter input when opening, so that screenreader can recognize the combobox\n if (isOpen && !prevOpen && hasSelectedOption && !hasFilter) {\n if (openedWithKeyboard) {\n highlightOptionWithKeyboard(__selectedOptions[0]);\n } else {\n setHighlightedIndexWithMouse(options.indexOf(__selectedOptions[0]), true);\n }\n }\n }, [\n isOpen,\n __selectedOptions,\n hasSelectedOption,\n setHighlightedIndexWithMouse,\n highlightOptionWithKeyboard,\n openedWithKeyboard,\n options,\n prevOpen,\n hasFilter,\n ]);\n\n useEffect(() => {\n if (isOpen && !embedded) {\n // dropdown-fit calculations ensure that the dropdown will fit inside the current\n // viewport, so prevent the browser from trying to scroll it into view (e.g. if\n // scroll-padding-top is set on a parent)\n activeRef.current?.focus({ preventScroll: true });\n }\n }, [isOpen, activeRef, embedded]);\n\n useForwardFocus(externalRef, triggerRef as React.RefObject<HTMLElement>);\n const highlightedGroupSelected =\n !!highlightedOption && isGroup(highlightedOption.option) && getGroupState(highlightedOption.option).selected;\n const announceSelected =\n !!highlightedOption && (__selectedOptions.indexOf(highlightedOption) > -1 || highlightedGroupSelected);\n\n return {\n isOpen,\n highlightedOption,\n highlightedIndex,\n highlightType,\n getTriggerProps,\n getDropdownProps,\n getMenuProps,\n getFilterProps,\n getOptionProps,\n highlightOption: highlightOptionWithKeyboard,\n selectOption,\n announceSelected,\n dialogId,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-select.js","sourceRoot":"","sources":["../../../../src/select/utils/use-select.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAM1C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uDAAuD,CAAC;AAEnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mEAAmE,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,C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ACL,4BAA4B,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aAC3E;SACF;IACH,CAAC,EAAE;QACD,MAAM;QACN,iBAAiB;QACjB,iBAAiB;QACjB,4BAA4B;QAC5B,2BAA2B;QAC3B,kBAAkB;QAClB,OAAO;QACP,QAAQ;QACR,SAAS;KACV,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;;QACb,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;YACvB,iFAAiF;YACjF,+EAA+E;YAC/E,yCAAyC;YACzC,MAAA,SAAS,CAAC,OAAO,0CAAE,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;SACnD;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IAElC,eAAe,CAAC,WAAW,EAAE,UAA0C,CAAC,CAAC;IACzE,MAAM,wBAAwB,GAC5B,CAAC,CAAC,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC;IAC/G,MAAM,gBAAgB,GACpB,CAAC,CAAC,iBAAiB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC;IAEzG,OAAO;QACL,MAAM;QACN,iBAAiB;QACjB,gBAAgB;QAChB,aAAa;QACb,eAAe;QACf,gBAAgB;QAChB,YAAY;QACZ,cAAc;QACd,cAAc;QACd,eAAe,EAAE,2BAA2B;QAC5C,YAAY;QACZ,gBAAgB;QAChB,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { RefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nimport { ButtonTriggerProps } from '../../internal/components/button-trigger';\nimport { DropdownProps } from '../../internal/components/dropdown/interfaces';\nimport { DropdownStatusProps } from '../../internal/components/dropdown-status';\nimport { DropdownOption, OptionDefinition, OptionGroup } from '../../internal/components/option/interfaces';\nimport { isGroup, isGroupInteractive, isInteractive } from '../../internal/components/option/utils/filter-options';\nimport { OptionsListProps } from '../../internal/components/options-list';\nimport { useHighlightedOption } from '../../internal/components/options-list/utils/use-highlight-option';\nimport { getOptionId } from '../../internal/components/options-list/utils/use-ids';\nimport { useMenuKeyboard, useTriggerKeyboard } from '../../internal/components/options-list/utils/use-keyboard';\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../../internal/events';\nimport useForwardFocus from '../../internal/hooks/forward-focus';\nimport { usePrevious } from '../../internal/hooks/use-previous';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id';\nimport { FilterProps } from '../parts/filter';\nimport { ItemProps } from '../parts/item';\nimport { connectOptionsByValue } from './connect-options';\n\nexport type MenuProps = Omit<OptionsListProps, 'children'> & { ref: React.RefObject<HTMLUListElement> };\nexport type GetOptionProps = (option: DropdownOption, index: number) => ItemProps;\n\ninterface UseSelectProps {\n selectedOptions: ReadonlyArray<OptionDefinition>;\n updateSelectedOption: (option: OptionDefinition) => void;\n options: ReadonlyArray<DropdownOption>;\n filteringType: string;\n keepOpen?: boolean;\n embedded?: boolean;\n onBlur?: NonCancelableEventHandler;\n onFocus?: NonCancelableEventHandler;\n externalRef: React.Ref<any>;\n fireLoadItems: (filteringText: string) => void;\n setFilteringValue?: (filteringText: string) => void;\n useInteractiveGroups?: boolean;\n statusType: DropdownStatusProps.StatusType;\n isAllSelected?: boolean;\n isSomeSelected?: boolean;\n toggleAll?: () => void;\n}\n\nexport interface SelectTriggerProps extends ButtonTriggerProps {\n ref: RefObject<HTMLButtonElement>;\n}\n\nexport function useSelect({\n selectedOptions,\n updateSelectedOption,\n options,\n filteringType,\n onBlur,\n onFocus,\n externalRef,\n keepOpen,\n embedded,\n fireLoadItems,\n setFilteringValue,\n useInteractiveGroups = false,\n statusType,\n isAllSelected,\n isSomeSelected,\n toggleAll,\n}: UseSelectProps) {\n const interactivityCheck = useInteractiveGroups ? isGroupInteractive : isInteractive;\n\n const isHighlightable = (option?: DropdownOption) => !!option && (useInteractiveGroups || option.type !== 'parent');\n\n const filterRef = useRef<HTMLInputElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const menuRef = useRef<HTMLUListElement>(null);\n const hasFilter = filteringType !== 'none' && !embedded;\n const activeRef = hasFilter ? filterRef : menuRef;\n const __selectedOptions = connectOptionsByValue(options, selectedOptions);\n const __selectedValuesSet = selectedOptions.reduce((selectedValuesSet: Set<string>, item: OptionDefinition) => {\n if (item.value) {\n selectedValuesSet.add(item.value);\n }\n return selectedValuesSet;\n }, new Set<string>());\n const [\n { highlightType, highlightedOption, highlightedIndex },\n {\n moveHighlightWithKeyboard,\n resetHighlightWithKeyboard,\n setHighlightedIndexWithMouse,\n highlightOptionWithKeyboard,\n goHomeWithKeyboard,\n goEndWithKeyboard,\n },\n ] = useHighlightedOption({ options: options, isHighlightable });\n\n const { isOpen, openDropdown, closeDropdown, toggleDropdown, openedWithKeyboard } = useOpenState({\n defaultOpen: embedded,\n onOpen: () => fireLoadItems(''),\n onClose: () => {\n resetHighlightWithKeyboard();\n setFilteringValue?.('');\n },\n });\n\n const handleFocus = () => {\n fireNonCancelableEvent(onFocus, {});\n };\n\n const handleBlur = () => {\n fireNonCancelableEvent(onBlur, {});\n closeDropdown();\n };\n\n const hasSelectedOption = __selectedOptions.length > 0;\n const menuId = useUniqueId('option-list');\n const dialogId = useUniqueId('dialog');\n const highlightedOptionId = getOptionId(menuId, highlightedIndex);\n\n const closeDropdownIfNecessary = () => {\n if (!keepOpen) {\n triggerRef.current?.focus();\n closeDropdown();\n }\n };\n\n const selectOption = (option?: DropdownOption) => {\n const optionToSelect = option || highlightedOption;\n if (!optionToSelect || !interactivityCheck(optionToSelect)) {\n return;\n }\n if (optionToSelect.type === 'select-all' && toggleAll) {\n toggleAll();\n } else {\n updateSelectedOption(optionToSelect.option);\n }\n closeDropdownIfNecessary();\n };\n\n const activeKeyDownHandler = useMenuKeyboard({\n goUp: () => {\n if (\n (!useInteractiveGroups && highlightedOption?.type === 'child' && highlightedIndex === 1) ||\n highlightedIndex === 0\n ) {\n goEndWithKeyboard();\n return;\n }\n moveHighlightWithKeyboard(-1);\n },\n goDown: () => {\n if (highlightedIndex === options.length - 1) {\n goHomeWithKeyboard();\n return;\n }\n\n moveHighlightWithKeyboard(1);\n },\n selectOption,\n goHome: goHomeWithKeyboard,\n goEnd: goEndWithKeyboard,\n closeDropdown: () => {\n if (!embedded) {\n triggerRef.current?.focus();\n closeDropdown();\n }\n },\n preventNativeSpace: !hasFilter || !!highlightedOption,\n });\n\n const triggerKeyDownHandler = useTriggerKeyboard({\n openDropdown: () => openDropdown(true),\n goHome: goHomeWithKeyboard,\n });\n\n const getDropdownProps: () => Pick<\n DropdownProps,\n 'onFocus' | 'onBlur' | 'dropdownContentId' | 'dropdownContentRole'\n > = () => ({\n onFocus: handleFocus,\n onBlur: handleBlur,\n dropdownContentId: dialogId,\n dropdownContentRole: hasFilter ? 'dialog' : undefined,\n });\n\n const getTriggerProps = (disabled = false, autoFocus = false) => {\n const triggerProps: SelectTriggerProps = {\n ref: triggerRef,\n onFocus: () => closeDropdown(),\n autoFocus,\n ariaHasPopup: hasFilter ? 'dialog' : 'listbox',\n ariaControls: isOpen ? (hasFilter ? dialogId : menuId) : undefined,\n };\n if (!disabled) {\n triggerProps.onMouseDown = (event: CustomEvent) => {\n event.preventDefault(); // prevent current focus from blurring as it immediately closes the dropdown\n if (isOpen) {\n triggerRef.current?.focus();\n }\n toggleDropdown();\n };\n triggerProps.onKeyDown = triggerKeyDownHandler;\n }\n return triggerProps;\n };\n\n const getFilterProps = (): Partial<FilterProps> => {\n if (!hasFilter || !setFilteringValue) {\n return {};\n }\n\n return {\n ref: filterRef,\n onKeyDown: activeKeyDownHandler,\n onChange: event => {\n setFilteringValue(event.detail.value);\n resetHighlightWithKeyboard();\n },\n __onDelayedInput: event => {\n fireLoadItems(event.detail.value);\n },\n __nativeAttributes: {\n 'aria-activedescendant': highlightedOptionId,\n ['aria-owns']: menuId,\n ['aria-controls']: menuId,\n },\n };\n };\n\n const getMenuProps = () => {\n const menuProps: MenuProps = {\n id: menuId,\n ref: menuRef,\n open: isOpen,\n onMouseUp: itemIndex => {\n if (itemIndex > -1) {\n selectOption(options[itemIndex]);\n }\n },\n onMouseMove: itemIndex => {\n if (itemIndex > -1) {\n setHighlightedIndexWithMouse(itemIndex);\n }\n },\n statusType,\n };\n if (!hasFilter) {\n menuProps.onKeyDown = activeKeyDownHandler;\n menuProps.nativeAttributes = {\n 'aria-activedescendant': highlightedOptionId,\n };\n }\n if (embedded) {\n menuProps.onFocus = () => {\n if (!highlightedOption) {\n goHomeWithKeyboard();\n }\n };\n menuProps.onBlur = () => {\n resetHighlightWithKeyboard();\n };\n }\n return menuProps;\n };\n const getGroupState = (option: OptionGroup) => {\n const totalSelected = option.options.filter(item => !!item.value && __selectedValuesSet.has(item.value)).length;\n const hasSelected = totalSelected > 0;\n const allSelected = totalSelected === option.options.length;\n return {\n selected: hasSelected && allSelected && useInteractiveGroups,\n indeterminate: hasSelected && !allSelected,\n };\n };\n\n const getOptionProps = (option: DropdownOption, index: number) => {\n const isSelectAll = option.type === 'select-all';\n const highlighted = option === highlightedOption;\n const groupState = isGroup(option.option) ? getGroupState(option.option) : undefined;\n const selected = isSelectAll ? isAllSelected : __selectedOptions.indexOf(option) > -1 || !!groupState?.selected;\n const nextOption = options[index + 1]?.option;\n const isNextSelected =\n !!nextOption && isGroup(nextOption)\n ? getGroupState(nextOption).selected\n : __selectedOptions.indexOf(options[index + 1]) > -1;\n const optionProps: any = {\n key: index,\n option,\n highlighted,\n selected,\n isNextSelected,\n indeterminate: !!groupState?.indeterminate || (isSelectAll && !isAllSelected && isSomeSelected),\n ['data-mouse-target']: isHighlightable(option) ? index : -1,\n id: getOptionId(menuId, index),\n };\n\n return optionProps;\n };\n\n const prevOpen = usePrevious<boolean>(isOpen);\n useEffect(() => {\n // highlight the first selected option, when opening the Select component without filter input\n // keep the focus in the filter input when opening, so that screenreader can recognize the combobox\n if (isOpen && !prevOpen && hasSelectedOption && !hasFilter) {\n if (openedWithKeyboard) {\n highlightOptionWithKeyboard(__selectedOptions[0]);\n } else {\n setHighlightedIndexWithMouse(options.indexOf(__selectedOptions[0]), true);\n }\n }\n }, [\n isOpen,\n __selectedOptions,\n hasSelectedOption,\n setHighlightedIndexWithMouse,\n highlightOptionWithKeyboard,\n openedWithKeyboard,\n options,\n prevOpen,\n hasFilter,\n ]);\n\n useEffect(() => {\n if (isOpen && !embedded) {\n // dropdown-fit calculations ensure that the dropdown will fit inside the current\n // viewport, so prevent the browser from trying to scroll it into view (e.g. if\n // scroll-padding-top is set on a parent)\n activeRef.current?.focus({ preventScroll: true });\n }\n }, [isOpen, activeRef, embedded]);\n\n useForwardFocus(externalRef, triggerRef as React.RefObject<HTMLElement>);\n const highlightedGroupSelected =\n !!highlightedOption && isGroup(highlightedOption.option) && getGroupState(highlightedOption.option).selected;\n const announceSelected =\n !!highlightedOption && (__selectedOptions.indexOf(highlightedOption) > -1 || highlightedGroupSelected);\n\n return {\n isOpen,\n highlightedOption,\n highlightedIndex,\n highlightType,\n getTriggerProps,\n getDropdownProps,\n getMenuProps,\n getFilterProps,\n getOptionProps,\n highlightOption: highlightOptionWithKeyboard,\n selectOption,\n announceSelected,\n dialogId,\n };\n}\n"]}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"expandable-toggle-wrapper": "awsui_expandable-toggle-
|
|
5
|
-
"body-cell": "awsui_body-
|
|
6
|
-
"body-cell-content": "awsui_body-cell-
|
|
7
|
-
"expandable-level-0": "awsui_expandable-level-
|
|
8
|
-
"expandable-level-1": "awsui_expandable-level-
|
|
9
|
-
"expandable-level-2": "awsui_expandable-level-
|
|
10
|
-
"expandable-level-3": "awsui_expandable-level-
|
|
11
|
-
"expandable-level-4": "awsui_expandable-level-
|
|
12
|
-
"expandable-level-5": "awsui_expandable-level-
|
|
13
|
-
"expandable-level-6": "awsui_expandable-level-
|
|
14
|
-
"expandable-level-7": "awsui_expandable-level-
|
|
15
|
-
"expandable-level-8": "awsui_expandable-level-
|
|
16
|
-
"expandable-level-9": "awsui_expandable-level-
|
|
17
|
-
"expandable-level-next": "awsui_expandable-level-
|
|
18
|
-
"body-cell-align-top": "awsui_body-cell-align-
|
|
19
|
-
"body-cell-wrap": "awsui_body-cell-
|
|
20
|
-
"is-visual-refresh": "awsui_is-visual-
|
|
21
|
-
"body-cell-edit-active": "awsui_body-cell-edit-
|
|
22
|
-
"body-cell-expandable": "awsui_body-cell-
|
|
23
|
-
"body-cell-editable": "awsui_body-cell-
|
|
24
|
-
"has-striped-rows": "awsui_has-striped-
|
|
25
|
-
"sticky-cell-pad-inline-start": "awsui_sticky-cell-pad-inline-
|
|
26
|
-
"has-selection": "awsui_has-
|
|
27
|
-
"body-cell-first-row": "awsui_body-cell-first-
|
|
28
|
-
"body-cell-last-row": "awsui_body-cell-last-
|
|
29
|
-
"body-cell-selected": "awsui_body-cell-
|
|
30
|
-
"has-footer": "awsui_has-
|
|
31
|
-
"body-cell-shaded": "awsui_body-cell-
|
|
32
|
-
"sticky-cell": "awsui_sticky-
|
|
33
|
-
"sticky-cell-last-inline-end": "awsui_sticky-cell-last-inline-
|
|
34
|
-
"sticky-cell-last-inline-start": "awsui_sticky-cell-last-inline-
|
|
35
|
-
"body-cell-next-selected": "awsui_body-cell-next-
|
|
36
|
-
"body-cell-prev-selected": "awsui_body-cell-prev-
|
|
37
|
-
"body-cell-editor-wrapper": "awsui_body-cell-editor-
|
|
38
|
-
"body-cell-success": "awsui_body-cell-
|
|
39
|
-
"body-cell-editor": "awsui_body-cell-
|
|
40
|
-
"body-cell-editor-disabled": "awsui_body-cell-editor-
|
|
41
|
-
"body-cell-editor-row": "awsui_body-cell-editor-
|
|
42
|
-
"body-cell-editor-controls": "awsui_body-cell-editor-
|
|
43
|
-
"body-cell-editor-row-editor": "awsui_body-cell-editor-row-
|
|
44
|
-
"body-cell-editor-focusable": "awsui_body-cell-editor-
|
|
45
|
-
"body-cell-editor-icon": "awsui_body-cell-editor-
|
|
46
|
-
"resizable-columns": "awsui_resizable-
|
|
47
|
-
"expandable-cell-content": "awsui_expandable-cell-
|
|
48
|
-
"body-cell-edit-disabled-popover": "awsui_body-cell-edit-disabled-
|
|
49
|
-
"body-cell-has-success": "awsui_body-cell-has-
|
|
4
|
+
"expandable-toggle-wrapper": "awsui_expandable-toggle-wrapper_c6tup_ejkv3_145",
|
|
5
|
+
"body-cell": "awsui_body-cell_c6tup_ejkv3_152",
|
|
6
|
+
"body-cell-content": "awsui_body-cell-content_c6tup_ejkv3_160",
|
|
7
|
+
"expandable-level-0": "awsui_expandable-level-0_c6tup_ejkv3_166",
|
|
8
|
+
"expandable-level-1": "awsui_expandable-level-1_c6tup_ejkv3_173",
|
|
9
|
+
"expandable-level-2": "awsui_expandable-level-2_c6tup_ejkv3_180",
|
|
10
|
+
"expandable-level-3": "awsui_expandable-level-3_c6tup_ejkv3_187",
|
|
11
|
+
"expandable-level-4": "awsui_expandable-level-4_c6tup_ejkv3_194",
|
|
12
|
+
"expandable-level-5": "awsui_expandable-level-5_c6tup_ejkv3_201",
|
|
13
|
+
"expandable-level-6": "awsui_expandable-level-6_c6tup_ejkv3_208",
|
|
14
|
+
"expandable-level-7": "awsui_expandable-level-7_c6tup_ejkv3_215",
|
|
15
|
+
"expandable-level-8": "awsui_expandable-level-8_c6tup_ejkv3_222",
|
|
16
|
+
"expandable-level-9": "awsui_expandable-level-9_c6tup_ejkv3_229",
|
|
17
|
+
"expandable-level-next": "awsui_expandable-level-next_c6tup_ejkv3_236",
|
|
18
|
+
"body-cell-align-top": "awsui_body-cell-align-top_c6tup_ejkv3_254",
|
|
19
|
+
"body-cell-wrap": "awsui_body-cell-wrap_c6tup_ejkv3_260",
|
|
20
|
+
"is-visual-refresh": "awsui_is-visual-refresh_c6tup_ejkv3_357",
|
|
21
|
+
"body-cell-edit-active": "awsui_body-cell-edit-active_c6tup_ejkv3_447",
|
|
22
|
+
"body-cell-expandable": "awsui_body-cell-expandable_c6tup_ejkv3_447",
|
|
23
|
+
"body-cell-editable": "awsui_body-cell-editable_c6tup_ejkv3_447",
|
|
24
|
+
"has-striped-rows": "awsui_has-striped-rows_c6tup_ejkv3_530",
|
|
25
|
+
"sticky-cell-pad-inline-start": "awsui_sticky-cell-pad-inline-start_c6tup_ejkv3_696",
|
|
26
|
+
"has-selection": "awsui_has-selection_c6tup_ejkv3_862",
|
|
27
|
+
"body-cell-first-row": "awsui_body-cell-first-row_c6tup_ejkv3_1031",
|
|
28
|
+
"body-cell-last-row": "awsui_body-cell-last-row_c6tup_ejkv3_1034",
|
|
29
|
+
"body-cell-selected": "awsui_body-cell-selected_c6tup_ejkv3_1034",
|
|
30
|
+
"has-footer": "awsui_has-footer_c6tup_ejkv3_1034",
|
|
31
|
+
"body-cell-shaded": "awsui_body-cell-shaded_c6tup_ejkv3_1044",
|
|
32
|
+
"sticky-cell": "awsui_sticky-cell_c6tup_ejkv3_696",
|
|
33
|
+
"sticky-cell-last-inline-end": "awsui_sticky-cell-last-inline-end_c6tup_ejkv3_1106",
|
|
34
|
+
"sticky-cell-last-inline-start": "awsui_sticky-cell-last-inline-start_c6tup_ejkv3_1115",
|
|
35
|
+
"body-cell-next-selected": "awsui_body-cell-next-selected_c6tup_ejkv3_1137",
|
|
36
|
+
"body-cell-prev-selected": "awsui_body-cell-prev-selected_c6tup_ejkv3_1144",
|
|
37
|
+
"body-cell-editor-wrapper": "awsui_body-cell-editor-wrapper_c6tup_ejkv3_1170",
|
|
38
|
+
"body-cell-success": "awsui_body-cell-success_c6tup_ejkv3_1175",
|
|
39
|
+
"body-cell-editor": "awsui_body-cell-editor_c6tup_ejkv3_1170",
|
|
40
|
+
"body-cell-editor-disabled": "awsui_body-cell-editor-disabled_c6tup_ejkv3_1200",
|
|
41
|
+
"body-cell-editor-row": "awsui_body-cell-editor-row_c6tup_ejkv3_1209",
|
|
42
|
+
"body-cell-editor-controls": "awsui_body-cell-editor-controls_c6tup_ejkv3_1219",
|
|
43
|
+
"body-cell-editor-row-editor": "awsui_body-cell-editor-row-editor_c6tup_ejkv3_1222",
|
|
44
|
+
"body-cell-editor-focusable": "awsui_body-cell-editor-focusable_c6tup_ejkv3_1225",
|
|
45
|
+
"body-cell-editor-icon": "awsui_body-cell-editor-icon_c6tup_ejkv3_1249",
|
|
46
|
+
"resizable-columns": "awsui_resizable-columns_c6tup_ejkv3_1361",
|
|
47
|
+
"expandable-cell-content": "awsui_expandable-cell-content_c6tup_ejkv3_1364",
|
|
48
|
+
"body-cell-edit-disabled-popover": "awsui_body-cell-edit-disabled-popover_c6tup_ejkv3_1415",
|
|
49
|
+
"body-cell-has-success": "awsui_body-cell-has-success_c6tup_ejkv3_1418"
|
|
50
50
|
};
|
|
51
51
|
|