@cloudscape-design/components-themeable 3.0.941 → 3.0.943
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/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/internal/components/selectable-item/styles.scss +4 -0
- package/lib/internal/scss/select/parts/styles.scss +5 -15
- package/lib/internal/template/app-layout/drawer/index.d.ts.map +1 -1
- package/lib/internal/template/app-layout/drawer/index.js +1 -1
- package/lib/internal/template/app-layout/drawer/index.js.map +1 -1
- package/lib/internal/template/app-layout/mobile-toolbar/index.d.ts.map +1 -1
- package/lib/internal/template/app-layout/mobile-toolbar/index.js +1 -1
- package/lib/internal/template/app-layout/mobile-toolbar/index.js.map +1 -1
- package/lib/internal/template/app-layout/visual-refresh/drawers.d.ts.map +1 -1
- package/lib/internal/template/app-layout/visual-refresh/drawers.js +2 -2
- package/lib/internal/template/app-layout/visual-refresh/drawers.js.map +1 -1
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.d.ts.map +1 -1
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.js +2 -2
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.js.map +1 -1
- package/lib/internal/template/internal/components/option/interfaces.d.ts +1 -1
- package/lib/internal/template/internal/components/option/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/components/option/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/option/utils/prepare-options.d.ts +1 -0
- package/lib/internal/template/internal/components/option/utils/prepare-options.d.ts.map +1 -1
- package/lib/internal/template/internal/components/option/utils/prepare-options.js +1 -0
- package/lib/internal/template/internal/components/option/utils/prepare-options.js.map +1 -1
- package/lib/internal/template/internal/components/options-list/index.d.ts +1 -0
- package/lib/internal/template/internal/components/options-list/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/options-list/index.js +2 -2
- package/lib/internal/template/internal/components/options-list/index.js.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/index.js +2 -1
- package/lib/internal/template/internal/components/selectable-item/index.js.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/interfaces.d.ts +1 -0
- package/lib/internal/template/internal/components/selectable-item/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/selectable-item/styles.css.js +20 -19
- package/lib/internal/template/internal/components/selectable-item/styles.scoped.css +41 -37
- package/lib/internal/template/internal/components/selectable-item/styles.selectors.js +20 -19
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/internal/environment.json +1 -1
- package/lib/internal/template/multiselect/interfaces.d.ts +11 -2
- package/lib/internal/template/multiselect/interfaces.d.ts.map +1 -1
- package/lib/internal/template/multiselect/interfaces.js.map +1 -1
- package/lib/internal/template/multiselect/internal.d.ts.map +1 -1
- package/lib/internal/template/multiselect/internal.js +5 -3
- package/lib/internal/template/multiselect/internal.js.map +1 -1
- package/lib/internal/template/multiselect/use-multiselect.d.ts +7 -4
- package/lib/internal/template/multiselect/use-multiselect.d.ts.map +1 -1
- package/lib/internal/template/multiselect/use-multiselect.js +33 -9
- package/lib/internal/template/multiselect/use-multiselect.js.map +1 -1
- package/lib/internal/template/select/internal.js +1 -1
- package/lib/internal/template/select/internal.js.map +1 -1
- package/lib/internal/template/select/parts/common.d.ts +2 -0
- package/lib/internal/template/select/parts/common.d.ts.map +1 -0
- package/lib/internal/template/select/parts/common.js +4 -0
- package/lib/internal/template/select/parts/common.js.map +1 -0
- package/lib/internal/template/select/parts/multiselect-item.d.ts.map +1 -1
- package/lib/internal/template/select/parts/multiselect-item.js +3 -2
- package/lib/internal/template/select/parts/multiselect-item.js.map +1 -1
- package/lib/internal/template/select/parts/plain-list.d.ts.map +1 -1
- package/lib/internal/template/select/parts/plain-list.js +22 -14
- package/lib/internal/template/select/parts/plain-list.js.map +1 -1
- package/lib/internal/template/select/parts/styles.css.js +20 -21
- package/lib/internal/template/select/parts/styles.scoped.css +26 -30
- package/lib/internal/template/select/parts/styles.selectors.js +20 -21
- package/lib/internal/template/select/parts/trigger.d.ts.map +1 -1
- package/lib/internal/template/select/parts/trigger.js +1 -1
- package/lib/internal/template/select/parts/trigger.js.map +1 -1
- package/lib/internal/template/select/parts/virtual-list.d.ts.map +1 -1
- package/lib/internal/template/select/parts/virtual-list.js +26 -9
- package/lib/internal/template/select/parts/virtual-list.js.map +1 -1
- package/lib/internal/template/select/utils/render-options.d.ts +4 -3
- package/lib/internal/template/select/utils/render-options.d.ts.map +1 -1
- package/lib/internal/template/select/utils/render-options.js +5 -5
- package/lib/internal/template/select/utils/render-options.js.map +1 -1
- package/lib/internal/template/select/utils/scroll-to-index.d.ts +5 -0
- package/lib/internal/template/select/utils/scroll-to-index.d.ts.map +1 -0
- package/lib/internal/template/select/utils/scroll-to-index.js +14 -0
- package/lib/internal/template/select/utils/scroll-to-index.js.map +1 -0
- package/lib/internal/template/select/utils/use-select.d.ts +4 -1
- package/lib/internal/template/select/utils/use-select.d.ts.map +1 -1
- package/lib/internal/template/select/utils/use-select.js +18 -9
- package/lib/internal/template/select/utils/use-select.js.map +1 -1
- package/lib/internal/template/test-utils/dom/internal/dropdown-host.d.ts +20 -2
- package/lib/internal/template/test-utils/dom/internal/dropdown-host.js +33 -2
- package/lib/internal/template/test-utils/dom/internal/dropdown-host.js.map +1 -1
- package/lib/internal/template/test-utils/selectors/internal/dropdown-host.d.ts +1 -0
- package/lib/internal/template/test-utils/selectors/internal/dropdown-host.js +6 -0
- package/lib/internal/template/test-utils/selectors/internal/dropdown-host.js.map +1 -1
- package/lib/internal/template/test-utils/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/multiselect/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KA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CAAC,cAAc,EAC/C,eAAe,EAAE,gBAAgB,CAAC,eAAe,EACjD,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,gBAAgB,CAAC,aAAa,EACnC,iBAAiB,EAAE,cAAc,CAAC,OAAO,KAAK,IAAI,EAClD,UAAU,EAAE,IAAI,EAChB,oBAAoB,EAAE,IAAI,EAC1B,mBAAmB,EAAE,gBAAgB,CAAC,YAAY,EAClD,aAAa,EAAE,gBAAgB,CAAC,aAAa,GAC7C,CACO;QAEV,UAAU,IAAI,CACb,oBAAC,kBAAkB,oBACb,gBAAgB,CAAC,aAAa,EAAE,IACpC,SAAS,EAAE,MAAM,CAAC,MAAM,EACxB,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,qBAAqB,EAClC,sBAAsB,EAAE,2BAA2B,EACnD,uBAAuB,EAAE,4BAA4B,EACrD,mBAAmB,EAAE,IAAI,EACzB,QAAQ,EAAE,QAAQ,IAClB,CACH;QAED,oBAAC,gBAAgB,IAAC,EAAE,EAAE,WAAW,IAAG,SAAS,CAAoB,CAC7D,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useState } from 'react';\nimport clsx from 'clsx';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { getBaseProps } from '../internal/base-component';\nimport Dropdown from '../internal/components/dropdown';\nimport DropdownFooter from '../internal/components/dropdown-footer/index.js';\nimport ScreenreaderOnly from '../internal/components/screenreader-only';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings';\nimport Filter from '../select/parts/filter';\nimport PlainList from '../select/parts/plain-list';\nimport Trigger from '../select/parts/trigger';\nimport VirtualList from '../select/parts/virtual-list';\nimport { TokenGroupProps } from '../token-group/interfaces';\nimport InternalTokenGroup from '../token-group/internal';\nimport { MultiselectProps } from './interfaces';\nimport { useMultiselect } from './use-multiselect';\n\nimport styles from './styles.css.js';\n\ntype InternalMultiselectProps = SomeRequired<\n MultiselectProps,\n 'options' | 'selectedOptions' | 'filteringType' | 'statusType' | 'keepOpen' | 'hideTokens'\n> &\n InternalBaseComponentProps;\n\nconst InternalMultiselect = React.forwardRef(\n (\n {\n options,\n filteringType,\n filteringPlaceholder,\n filteringAriaLabel,\n filteringClearAriaLabel,\n ariaRequired,\n placeholder,\n disabled,\n readOnly,\n ariaLabel,\n selectedOptions,\n deselectAriaLabel,\n tokenLimit,\n i18nStrings,\n virtualScroll,\n inlineTokens = false,\n hideTokens,\n expandToViewport,\n tokenLimitShowFewerAriaLabel,\n tokenLimitShowMoreAriaLabel,\n __internalRootRef = null,\n autoFocus,\n ...restProps\n }: InternalMultiselectProps,\n externalRef: React.Ref<MultiselectProps.Ref>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n const i18n = useInternalI18n('multiselect');\n\n const selfControlId = useUniqueId('trigger');\n const controlId = formFieldContext.controlId ?? selfControlId;\n const ariaLabelId = useUniqueId('multiselect-ariaLabel-');\n const footerId = useUniqueId('multiselect-footer-');\n\n const [filteringValue, setFilteringValue] = useState('');\n const multiselectProps = useMultiselect({\n options,\n selectedOptions,\n filteringType,\n disabled,\n deselectAriaLabel,\n controlId,\n ariaLabelId,\n footerId,\n filteringValue,\n setFilteringValue,\n externalRef,\n ...restProps,\n });\n\n const filter = (\n <Filter\n clearAriaLabel={filteringClearAriaLabel}\n filteringType={filteringType}\n placeholder={filteringPlaceholder}\n ariaLabel={filteringAriaLabel}\n ariaRequired={ariaRequired}\n value={filteringValue}\n {...multiselectProps.getFilterProps()}\n />\n );\n\n const trigger = (\n <Trigger\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readOnly}\n triggerProps={multiselectProps.getTriggerProps(disabled, autoFocus)}\n selectedOption={null}\n selectedOptions={selectedOptions}\n triggerVariant={inlineTokens ? 'tokens' : 'placeholder'}\n isOpen={multiselectProps.isOpen}\n {...formFieldContext}\n controlId={controlId}\n ariaLabelledby={joinStrings(formFieldContext.ariaLabelledby, ariaLabelId)}\n />\n );\n\n const tokens: TokenGroupProps['items'] = selectedOptions.map(option => ({\n label: option.label,\n disabled: disabled || option.disabled,\n labelTag: option.labelTag,\n description: option.description,\n iconAlt: option.iconAlt,\n iconName: option.iconName,\n iconUrl: option.iconUrl,\n iconSvg: option.iconSvg,\n tags: option.tags,\n dismissLabel: i18n('deselectAriaLabel', deselectAriaLabel?.(option), format =>\n format({ option__label: option.label ?? '' })\n ),\n }));\n\n const ListComponent = virtualScroll ? VirtualList : PlainList;\n\n const showTokens = !hideTokens && !inlineTokens && tokens.length > 0;\n\n const tokenGroupI18nStrings: TokenGroupProps.I18nStrings = {\n limitShowFewer: i18nStrings?.tokenLimitShowFewer,\n limitShowMore: i18nStrings?.tokenLimitShowMore,\n };\n\n const dropdownStatus = multiselectProps.dropdownStatus;\n const dropdownProps = multiselectProps.getDropdownProps();\n\n return (\n <div\n {...baseProps}\n ref={__internalRootRef}\n className={clsx(styles.root, baseProps.className)}\n {...multiselectProps.getWrapperProps()}\n >\n <Dropdown\n {...dropdownProps}\n ariaLabelledby={dropdownProps.dropdownContentRole ? joinStrings(ariaLabelId, controlId) : undefined}\n ariaDescribedby={\n dropdownProps.dropdownContentRole ? (dropdownStatus.content ? footerId : undefined) : undefined\n }\n open={multiselectProps.isOpen}\n trigger={trigger}\n header={filter}\n footer={\n dropdownStatus.isSticky ? (\n <DropdownFooter content={multiselectProps.isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n expandToViewport={expandToViewport}\n stretchBeyondTriggerWidth={true}\n >\n <ListComponent\n listBottom={\n !dropdownStatus.isSticky ? (\n <DropdownFooter content={multiselectProps.isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n menuProps={multiselectProps.getMenuProps()}\n getOptionProps={multiselectProps.getOptionProps}\n filteredOptions={multiselectProps.filteredOptions}\n filteringValue={filteringValue}\n ref={multiselectProps.scrollToIndex}\n hasDropdownStatus={dropdownStatus.content !== null}\n checkboxes={true}\n useInteractiveGroups={true}\n screenReaderContent={multiselectProps.announcement}\n highlightType={multiselectProps.highlightType}\n />\n </Dropdown>\n\n {showTokens && (\n <InternalTokenGroup\n {...multiselectProps.getTokenProps()}\n className={styles.tokens}\n alignment=\"horizontal\"\n limit={tokenLimit}\n items={tokens}\n i18nStrings={tokenGroupI18nStrings}\n limitShowMoreAriaLabel={tokenLimitShowMoreAriaLabel}\n limitShowFewerAriaLabel={tokenLimitShowFewerAriaLabel}\n disableOuterPadding={true}\n readOnly={readOnly}\n />\n )}\n\n <ScreenreaderOnly id={ariaLabelId}>{ariaLabel}</ScreenreaderOnly>\n </div>\n );\n }\n);\n\nexport default InternalMultiselect;\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/multiselect/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,cAAc,MAAM,iDAAiD,CAAC;AAC7E,OAAO,gBAAgB,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA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AE,MAAM,CAAC,MAAM,EACxB,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,qBAAqB,EAClC,sBAAsB,EAAE,2BAA2B,EACnD,uBAAuB,EAAE,4BAA4B,EACrD,mBAAmB,EAAE,IAAI,EACzB,QAAQ,EAAE,QAAQ,IAClB,CACH;QAED,oBAAC,gBAAgB,IAAC,EAAE,EAAE,WAAW,IAAG,SAAS,CAAoB,CAC7D,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useState } from 'react';\nimport clsx from 'clsx';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { getBaseProps } from '../internal/base-component';\nimport Dropdown from '../internal/components/dropdown';\nimport DropdownFooter from '../internal/components/dropdown-footer/index.js';\nimport ScreenreaderOnly from '../internal/components/screenreader-only';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings';\nimport Filter from '../select/parts/filter';\nimport PlainList from '../select/parts/plain-list';\nimport Trigger from '../select/parts/trigger';\nimport VirtualList from '../select/parts/virtual-list';\nimport { TokenGroupProps } from '../token-group/interfaces';\nimport InternalTokenGroup from '../token-group/internal';\nimport { MultiselectProps } from './interfaces';\nimport { useMultiselect } from './use-multiselect';\n\nimport styles from './styles.css.js';\n\ntype InternalMultiselectProps = SomeRequired<\n MultiselectProps,\n 'options' | 'selectedOptions' | 'filteringType' | 'statusType' | 'keepOpen' | 'hideTokens'\n> &\n InternalBaseComponentProps;\n\nconst InternalMultiselect = React.forwardRef(\n (\n {\n options,\n filteringType,\n filteringPlaceholder,\n filteringAriaLabel,\n filteringClearAriaLabel,\n ariaRequired,\n placeholder,\n disabled,\n readOnly,\n ariaLabel,\n selectedOptions,\n deselectAriaLabel,\n tokenLimit,\n i18nStrings,\n virtualScroll,\n inlineTokens = false,\n hideTokens,\n expandToViewport,\n tokenLimitShowFewerAriaLabel,\n tokenLimitShowMoreAriaLabel,\n __internalRootRef = null,\n autoFocus,\n enableSelectAll,\n ...restProps\n }: InternalMultiselectProps,\n externalRef: React.Ref<MultiselectProps.Ref>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n const i18n = useInternalI18n('multiselect');\n\n const selfControlId = useUniqueId('trigger');\n const controlId = formFieldContext.controlId ?? selfControlId;\n const ariaLabelId = useUniqueId('multiselect-ariaLabel-');\n const footerId = useUniqueId('multiselect-footer-');\n\n const [filteringValue, setFilteringValue] = useState('');\n const multiselectProps = useMultiselect({\n options,\n selectedOptions,\n filteringType,\n disabled,\n deselectAriaLabel,\n controlId,\n ariaLabelId,\n footerId,\n filteringValue,\n setFilteringValue,\n externalRef,\n enableSelectAll,\n i18nStrings,\n ...restProps,\n });\n\n const filter = (\n <Filter\n clearAriaLabel={filteringClearAriaLabel}\n filteringType={filteringType}\n placeholder={filteringPlaceholder}\n ariaLabel={filteringAriaLabel}\n ariaRequired={ariaRequired}\n value={filteringValue}\n {...multiselectProps.getFilterProps()}\n />\n );\n\n const trigger = (\n <Trigger\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readOnly}\n triggerProps={multiselectProps.getTriggerProps(disabled, autoFocus)}\n selectedOption={null}\n selectedOptions={selectedOptions}\n triggerVariant={inlineTokens ? 'tokens' : 'placeholder'}\n isOpen={multiselectProps.isOpen}\n {...formFieldContext}\n controlId={controlId}\n ariaLabelledby={joinStrings(formFieldContext.ariaLabelledby, ariaLabelId)}\n />\n );\n\n const tokens: TokenGroupProps['items'] = selectedOptions.map(option => ({\n label: option.label,\n disabled: disabled || option.disabled,\n labelTag: option.labelTag,\n description: option.description,\n iconAlt: option.iconAlt,\n iconName: option.iconName,\n iconUrl: option.iconUrl,\n iconSvg: option.iconSvg,\n tags: option.tags,\n dismissLabel: i18n('deselectAriaLabel', deselectAriaLabel?.(option), format =>\n format({ option__label: option.label ?? '' })\n ),\n }));\n\n const ListComponent = virtualScroll ? VirtualList : PlainList;\n\n const showTokens = !hideTokens && !inlineTokens && tokens.length > 0;\n\n const tokenGroupI18nStrings: TokenGroupProps.I18nStrings = {\n limitShowFewer: i18nStrings?.tokenLimitShowFewer,\n limitShowMore: i18nStrings?.tokenLimitShowMore,\n };\n\n const dropdownStatus = multiselectProps.dropdownStatus;\n const dropdownProps = multiselectProps.getDropdownProps();\n\n return (\n <div\n {...baseProps}\n ref={__internalRootRef}\n className={clsx(styles.root, baseProps.className)}\n {...multiselectProps.getWrapperProps()}\n >\n <Dropdown\n {...dropdownProps}\n ariaLabelledby={dropdownProps.dropdownContentRole ? joinStrings(ariaLabelId, controlId) : undefined}\n ariaDescribedby={\n dropdownProps.dropdownContentRole ? (dropdownStatus.content ? footerId : undefined) : undefined\n }\n open={multiselectProps.isOpen}\n trigger={trigger}\n header={filter}\n footer={\n dropdownStatus.isSticky ? (\n <DropdownFooter content={multiselectProps.isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n expandToViewport={expandToViewport}\n stretchBeyondTriggerWidth={true}\n >\n <ListComponent\n listBottom={\n !dropdownStatus.isSticky ? (\n <DropdownFooter content={multiselectProps.isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n menuProps={multiselectProps.getMenuProps()}\n getOptionProps={multiselectProps.getOptionProps}\n filteredOptions={multiselectProps.filteredOptions}\n filteringValue={filteringValue}\n ref={multiselectProps.scrollToIndex}\n hasDropdownStatus={dropdownStatus.content !== null}\n checkboxes={true}\n useInteractiveGroups={true}\n screenReaderContent={multiselectProps.announcement}\n highlightType={multiselectProps.highlightType}\n firstOptionSticky={enableSelectAll}\n />\n </Dropdown>\n\n {showTokens && (\n <InternalTokenGroup\n {...multiselectProps.getTokenProps()}\n className={styles.tokens}\n alignment=\"horizontal\"\n limit={tokenLimit}\n items={tokens}\n i18nStrings={tokenGroupI18nStrings}\n limitShowMoreAriaLabel={tokenLimitShowMoreAriaLabel}\n limitShowFewerAriaLabel={tokenLimitShowFewerAriaLabel}\n disableOuterPadding={true}\n readOnly={readOnly}\n />\n )}\n\n <ScreenreaderOnly id={ariaLabelId}>{ariaLabel}</ScreenreaderOnly>\n </div>\n );\n }\n);\n\nexport default InternalMultiselect;\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DropdownStatusProps } from '../internal/components/dropdown-status';
|
|
3
|
+
import { DropdownOption } from '../internal/components/option/interfaces';
|
|
3
4
|
import { SomeRequired } from '../internal/types';
|
|
4
5
|
import { SelectListProps } from '../select/parts/plain-list';
|
|
5
6
|
import { TokenGroupProps } from '../token-group/interfaces';
|
|
6
7
|
import { MultiselectProps } from './interfaces';
|
|
7
|
-
type UseMultiselectOptions = SomeRequired<Pick<MultiselectProps, 'options' | 'selectedOptions' | 'filteringType' | 'filteringResultsText' | 'disabled' | 'noMatch' | 'renderHighlightedAriaLive' | 'deselectAriaLabel' | 'keepOpen' | 'onBlur' | 'onFocus' | 'onLoadItems' | 'onChange' | 'selectedAriaLabel'> & DropdownStatusProps & {
|
|
8
|
+
type UseMultiselectOptions = SomeRequired<Pick<MultiselectProps, 'options' | 'selectedOptions' | 'filteringType' | 'filteringResultsText' | 'disabled' | 'noMatch' | 'renderHighlightedAriaLive' | 'deselectAriaLabel' | 'keepOpen' | 'onBlur' | 'onFocus' | 'onLoadItems' | 'onChange' | 'selectedAriaLabel' | 'enableSelectAll' | 'i18nStrings'> & DropdownStatusProps & {
|
|
8
9
|
controlId?: string;
|
|
9
10
|
ariaLabelId: string;
|
|
10
11
|
footerId: string;
|
|
@@ -14,13 +15,13 @@ type UseMultiselectOptions = SomeRequired<Pick<MultiselectProps, 'options' | 'se
|
|
|
14
15
|
}, 'options' | 'selectedOptions' | 'filteringType' | 'statusType' | 'keepOpen'> & {
|
|
15
16
|
embedded?: boolean;
|
|
16
17
|
};
|
|
17
|
-
export declare function useMultiselect({ options, filteringType, filteringResultsText, disabled, statusType, empty, loadingText, finishedText, errorText, noMatch, renderHighlightedAriaLive, selectedOptions, deselectAriaLabel, keepOpen, onBlur, onFocus, onLoadItems, onChange, controlId, ariaLabelId, footerId, filteringValue, setFilteringValue, externalRef, embedded, ...restProps }: UseMultiselectOptions): {
|
|
18
|
+
export declare function useMultiselect({ options, filteringType, filteringResultsText, disabled, statusType, empty, loadingText, finishedText, errorText, noMatch, renderHighlightedAriaLive, selectedOptions, deselectAriaLabel, keepOpen, onBlur, onFocus, onLoadItems, onChange, controlId, ariaLabelId, footerId, filteringValue, setFilteringValue, externalRef, embedded, enableSelectAll, i18nStrings, ...restProps }: UseMultiselectOptions): {
|
|
18
19
|
isOpen: boolean;
|
|
19
20
|
tokens: readonly TokenGroupProps.Item[];
|
|
20
21
|
announcement: string;
|
|
21
22
|
dropdownStatus: import("../internal/components/dropdown-status").DropdownStatusResult;
|
|
22
23
|
filteringValue: string;
|
|
23
|
-
filteredOptions: readonly
|
|
24
|
+
filteredOptions: readonly DropdownOption[];
|
|
24
25
|
highlightType: import("../internal/components/options-list/utils/use-highlight-option").HighlightType;
|
|
25
26
|
scrollToIndex: React.RefObject<SelectListProps.SelectListRef>;
|
|
26
27
|
getFilterProps: () => Partial<import("../select/parts/filter").FilterProps>;
|
|
@@ -46,9 +47,10 @@ export declare function useMultiselect({ options, filteringType, filteringResult
|
|
|
46
47
|
statusType: DropdownStatusProps.StatusType;
|
|
47
48
|
nativeAttributes?: Record<string, any> | undefined;
|
|
48
49
|
decreaseBlockMargin?: boolean | undefined;
|
|
50
|
+
stickyItemBlockSize?: number | null | undefined;
|
|
49
51
|
ref: React.RefObject<HTMLUListElement>;
|
|
50
52
|
};
|
|
51
|
-
getOptionProps: (option:
|
|
53
|
+
getOptionProps: (option: DropdownOption, index: number) => any;
|
|
52
54
|
getTokenProps: () => {
|
|
53
55
|
onDismiss: import("../internal/events").NonCancelableEventHandler<TokenGroupProps.DismissDetail>;
|
|
54
56
|
};
|
|
@@ -62,6 +64,7 @@ export declare function useMultiselect({ options, filteringType, filteringResult
|
|
|
62
64
|
getWrapperProps: () => {
|
|
63
65
|
onKeyDown: (event: React.KeyboardEvent<Element>) => void;
|
|
64
66
|
};
|
|
67
|
+
highlightedIndex: number;
|
|
65
68
|
};
|
|
66
69
|
export {};
|
|
67
70
|
//# sourceMappingURL=use-multiselect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multiselect.d.ts","sourceRoot":"","sources":["../../../src/multiselect/use-multiselect.tsx"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-multiselect.d.ts","sourceRoot":"","sources":["../../../src/multiselect/use-multiselect.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAKvE,OAAO,EAAE,mBAAmB,EAAqB,MAAM,wCAAwC,CAAC;AAChG,OAAO,EAAE,cAAc,EAAiC,MAAM,0CAA0C,CAAC;AAIzG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAO7D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,KAAK,qBAAqB,GAAG,YAAY,CACvC,IAAI,CACF,gBAAgB,EACd,SAAS,GACT,iBAAiB,GACjB,eAAe,GACf,sBAAsB,GACtB,UAAU,GACV,SAAS,GACT,2BAA2B,GAC3B,mBAAmB,GACnB,UAAU,GACV,QAAQ,GACR,SAAS,GACT,aAAa,GACb,UAAU,GACV,mBAAmB,GACnB,iBAAiB,GACjB,aAAa,CAChB,GACC,mBAAmB,GAAG;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;CAC9C,EACH,SAAS,GAAG,iBAAiB,GAAG,eAAe,GAAG,YAAY,GAAG,UAAU,CAC5E,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE3B,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,aAAa,EACb,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,OAAO,EACP,yBAAyB,EACzB,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,SAAS,EACT,WAAW,EACX,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,eAAe,EACf,WAAW,EACX,GAAG,SAAS,EACb,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAuLc,gBAAgB;;;;;;;;;;EA0CrD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { __rest } from "tslib";
|
|
4
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
|
|
6
6
|
import { useInternalI18n } from '../i18n/context';
|
|
7
7
|
import { useDropdownStatus } from '../internal/components/dropdown-status';
|
|
@@ -16,7 +16,7 @@ import { useLoadItems } from '../select/utils/use-load-items';
|
|
|
16
16
|
import { useNativeSearch } from '../select/utils/use-native-search';
|
|
17
17
|
import { useSelect } from '../select/utils/use-select';
|
|
18
18
|
export function useMultiselect(_a) {
|
|
19
|
-
var { options, filteringType, filteringResultsText, disabled, statusType, empty, loadingText, finishedText, errorText, noMatch, renderHighlightedAriaLive, selectedOptions, deselectAriaLabel, keepOpen, onBlur, onFocus, onLoadItems, onChange, controlId, ariaLabelId, footerId, filteringValue, setFilteringValue, externalRef, embedded } = _a, restProps = __rest(_a, ["options", "filteringType", "filteringResultsText", "disabled", "statusType", "empty", "loadingText", "finishedText", "errorText", "noMatch", "renderHighlightedAriaLive", "selectedOptions", "deselectAriaLabel", "keepOpen", "onBlur", "onFocus", "onLoadItems", "onChange", "controlId", "ariaLabelId", "footerId", "filteringValue", "setFilteringValue", "externalRef", "embedded"]);
|
|
19
|
+
var { options, filteringType, filteringResultsText, disabled, statusType, empty, loadingText, finishedText, errorText, noMatch, renderHighlightedAriaLive, selectedOptions, deselectAriaLabel, keepOpen, onBlur, onFocus, onLoadItems, onChange, controlId, ariaLabelId, footerId, filteringValue, setFilteringValue, externalRef, embedded, enableSelectAll, i18nStrings } = _a, restProps = __rest(_a, ["options", "filteringType", "filteringResultsText", "disabled", "statusType", "empty", "loadingText", "finishedText", "errorText", "noMatch", "renderHighlightedAriaLive", "selectedOptions", "deselectAriaLabel", "keepOpen", "onBlur", "onFocus", "onLoadItems", "onChange", "controlId", "ariaLabelId", "footerId", "filteringValue", "setFilteringValue", "externalRef", "embedded", "enableSelectAll", "i18nStrings"]);
|
|
20
20
|
checkOptionValueField('Multiselect', 'options', options);
|
|
21
21
|
const i18n = useInternalI18n('multiselect');
|
|
22
22
|
const i18nCommon = useInternalI18n('select');
|
|
@@ -32,9 +32,29 @@ export function useMultiselect(_a) {
|
|
|
32
32
|
statusType,
|
|
33
33
|
});
|
|
34
34
|
const useInteractiveGroups = true;
|
|
35
|
-
const { filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(options, filteringType, filteringValue);
|
|
35
|
+
const { flatOptions, filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(options, filteringType, filteringValue);
|
|
36
|
+
const selectAllOption = {
|
|
37
|
+
type: 'select-all',
|
|
38
|
+
afterHeader: filteringType !== 'none',
|
|
39
|
+
option: { label: i18n('i18nStrings.selectAllText', i18nStrings === null || i18nStrings === void 0 ? void 0 : i18nStrings.selectAllText) },
|
|
40
|
+
};
|
|
41
|
+
const visibleOptions = enableSelectAll && filteredOptions.length ? [selectAllOption, ...filteredOptions] : filteredOptions;
|
|
42
|
+
// Includes visible and non-visible (filtered out) options
|
|
43
|
+
const allNonParentOptions = flatOptions.filter(item => item.type !== 'parent').map(option => option.option);
|
|
44
|
+
const filteredNonParentOptions = filteredOptions.filter(item => item.type !== 'parent').map(item => item.option);
|
|
45
|
+
const selectedValues = useMemo(() => new Set(selectedOptions.map(option => option.value)), [selectedOptions]);
|
|
46
|
+
const isSomeSelected = selectedOptions.length > 0;
|
|
47
|
+
const isAllVisibleSelectableSelected = isSomeSelected && filteredNonParentOptions.every(option => option.disabled || selectedValues.has(option.value));
|
|
48
|
+
const isAllSelected = allNonParentOptions.every(option => selectedValues.has(option.value));
|
|
49
|
+
const toggleAll = () => {
|
|
50
|
+
const filteredNonParentOptionValues = new Set(filteredNonParentOptions.map(option => option.value));
|
|
51
|
+
fireNonCancelableEvent(onChange, {
|
|
52
|
+
selectedOptions: isAllVisibleSelectableSelected
|
|
53
|
+
? selectedOptions.filter(option => !filteredNonParentOptionValues.has(option.value))
|
|
54
|
+
: allNonParentOptions.filter(({ disabled, value }) => selectedValues.has(value) || (!disabled && filteredNonParentOptionValues.has(value))),
|
|
55
|
+
});
|
|
56
|
+
};
|
|
36
57
|
const updateSelectedOption = useCallback((option) => {
|
|
37
|
-
const filtered = filteredOptions.filter(item => item.type !== 'parent').map(item => item.option);
|
|
38
58
|
// switch between selection and deselection behavior, ignores disabled options to prevent
|
|
39
59
|
// getting stuck on one behavior when an option is disabled and its state cannot be changed
|
|
40
60
|
const isAllChildrenSelected = (optionsArray) => optionsArray.every(item => findOptionIndex(selectedOptions, item) > -1 || item.disabled);
|
|
@@ -48,7 +68,7 @@ export function useMultiselect(_a) {
|
|
|
48
68
|
};
|
|
49
69
|
let newSelectedOptions = [...selectedOptions];
|
|
50
70
|
if (isGroup(option)) {
|
|
51
|
-
const visibleOptions = intersection([...option.options],
|
|
71
|
+
const visibleOptions = intersection([...option.options], filteredNonParentOptions);
|
|
52
72
|
newSelectedOptions = isAllChildrenSelected(visibleOptions)
|
|
53
73
|
? unselect(visibleOptions, newSelectedOptions)
|
|
54
74
|
: select(visibleOptions, newSelectedOptions);
|
|
@@ -61,12 +81,12 @@ export function useMultiselect(_a) {
|
|
|
61
81
|
fireNonCancelableEvent(onChange, {
|
|
62
82
|
selectedOptions: newSelectedOptions,
|
|
63
83
|
});
|
|
64
|
-
}, [
|
|
84
|
+
}, [selectedOptions, onChange, filteredNonParentOptions]);
|
|
65
85
|
const scrollToIndex = useRef(null);
|
|
66
86
|
const { isOpen, highlightType, highlightedOption, highlightedIndex, getTriggerProps, getDropdownProps, getFilterProps, getMenuProps, getOptionProps, highlightOption, announceSelected, } = useSelect({
|
|
67
87
|
selectedOptions,
|
|
68
88
|
updateSelectedOption,
|
|
69
|
-
options:
|
|
89
|
+
options: visibleOptions,
|
|
70
90
|
filteringType,
|
|
71
91
|
onFocus,
|
|
72
92
|
onBlur,
|
|
@@ -77,10 +97,13 @@ export function useMultiselect(_a) {
|
|
|
77
97
|
useInteractiveGroups,
|
|
78
98
|
statusType,
|
|
79
99
|
embedded,
|
|
100
|
+
isAllSelected,
|
|
101
|
+
isSomeSelected,
|
|
102
|
+
toggleAll,
|
|
80
103
|
});
|
|
81
104
|
const wrapperOnKeyDown = useNativeSearch({
|
|
82
105
|
isEnabled: filteringType === 'none' && isOpen,
|
|
83
|
-
options:
|
|
106
|
+
options: visibleOptions,
|
|
84
107
|
highlightOption: highlightOption,
|
|
85
108
|
highlightedOption: highlightedOption === null || highlightedOption === void 0 ? void 0 : highlightedOption.option,
|
|
86
109
|
useInteractiveGroups,
|
|
@@ -149,7 +172,7 @@ export function useMultiselect(_a) {
|
|
|
149
172
|
announcement,
|
|
150
173
|
dropdownStatus,
|
|
151
174
|
filteringValue,
|
|
152
|
-
filteredOptions,
|
|
175
|
+
filteredOptions: visibleOptions,
|
|
153
176
|
highlightType,
|
|
154
177
|
scrollToIndex,
|
|
155
178
|
getFilterProps,
|
|
@@ -159,6 +182,7 @@ export function useMultiselect(_a) {
|
|
|
159
182
|
getTokenProps: () => ({ onDismiss: tokenOnDismiss }),
|
|
160
183
|
getDropdownProps: () => (Object.assign(Object.assign({}, getDropdownProps()), { onMouseDown: dropdownOnMouseDown })),
|
|
161
184
|
getWrapperProps: () => ({ onKeyDown: wrapperOnKeyDown }),
|
|
185
|
+
highlightedIndex,
|
|
162
186
|
};
|
|
163
187
|
}
|
|
164
188
|
//# sourceMappingURL=use-multiselect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multiselect.js","sourceRoot":"","sources":["../../../src/multiselect/use-multiselect.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAuB,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,oDAAoD,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,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M,cAAc,GAAiC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QAClE,MAAM,gBAAgB,GAAG,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC,GAAG,CAAC;QACxC,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;SAC3B;IACH,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,MAAM;QACN,YAAY;QACZ,cAAc;QACd,cAAc;QACd,eAAe;QACf,aAAa;QACb,aAAa;QACb,cAAc;QACd,eAAe;QACf,YAAY,EAAE,GAAG,EAAE,CAAC,iCACf,YAAY,EAAE,KACjB,UAAU,EAAE,cAAc,EAC1B,cAAc,EAAE,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,EACnD,eAAe,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAC9D,QAAQ,IACR;QACF,cAAc;QACd,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;QACpD,gBAAgB,EAAE,GAAG,EAAE,CAAC,iCAAM,gBAAgB,EAAE,KAAE,WAAW,EAAE,mBAAmB,IAAG;QACrF,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useCallback, useEffect, useRef } from 'react';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { DropdownStatusProps, useDropdownStatus } from '../internal/components/dropdown-status';\nimport { OptionDefinition, OptionGroup } from '../internal/components/option/interfaces';\nimport { isGroup } from '../internal/components/option/utils/filter-options';\nimport { prepareOptions } from '../internal/components/option/utils/prepare-options';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings';\nimport { SelectListProps } from '../select/parts/plain-list';\nimport { checkOptionValueField } from '../select/utils/check-option-value-field.js';\nimport { findOptionIndex } from '../select/utils/connect-options';\nimport { useAnnouncement } from '../select/utils/use-announcement';\nimport { useLoadItems } from '../select/utils/use-load-items';\nimport { useNativeSearch } from '../select/utils/use-native-search';\nimport { useSelect } from '../select/utils/use-select';\nimport { TokenGroupProps } from '../token-group/interfaces';\nimport { MultiselectProps } from './interfaces';\n\ntype UseMultiselectOptions = SomeRequired<\n Pick<\n MultiselectProps,\n | 'options'\n | 'selectedOptions'\n | 'filteringType'\n | 'filteringResultsText'\n | 'disabled'\n | 'noMatch'\n | 'renderHighlightedAriaLive'\n | 'deselectAriaLabel'\n | 'keepOpen'\n | 'onBlur'\n | 'onFocus'\n | 'onLoadItems'\n | 'onChange'\n | 'selectedAriaLabel'\n > &\n DropdownStatusProps & {\n controlId?: string;\n ariaLabelId: string;\n footerId: string;\n filteringValue: string;\n setFilteringValue?: (value: string) => void;\n externalRef: React.Ref<MultiselectProps.Ref>;\n },\n 'options' | 'selectedOptions' | 'filteringType' | 'statusType' | 'keepOpen'\n> & { embedded?: boolean };\n\nexport function useMultiselect({\n options,\n filteringType,\n filteringResultsText,\n disabled,\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n noMatch,\n renderHighlightedAriaLive,\n selectedOptions,\n deselectAriaLabel,\n keepOpen,\n onBlur,\n onFocus,\n onLoadItems,\n onChange,\n controlId,\n ariaLabelId,\n footerId,\n filteringValue,\n setFilteringValue,\n externalRef,\n embedded,\n ...restProps\n}: UseMultiselectOptions) {\n checkOptionValueField('Multiselect', 'options', options);\n\n const i18n = useInternalI18n('multiselect');\n const i18nCommon = useInternalI18n('select');\n const recoveryText = i18nCommon('recoveryText', restProps.recoveryText);\n const errorIconAriaLabel = i18nCommon('errorIconAriaLabel', restProps.errorIconAriaLabel);\n const selectedAriaLabel = i18nCommon('selectedAriaLabel', restProps.selectedAriaLabel);\n\n if (restProps.recoveryText && !onLoadItems) {\n warnOnce('Multiselect', '`onLoadItems` must be provided for `recoveryText` to be displayed.');\n }\n\n const { handleLoadMore, handleRecoveryClick, fireLoadItems } = useLoadItems({\n onLoadItems,\n options,\n statusType,\n });\n const useInteractiveGroups = true;\n const { filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(\n options,\n filteringType,\n filteringValue\n );\n\n const updateSelectedOption = useCallback(\n (option: OptionDefinition | OptionGroup) => {\n const filtered = filteredOptions.filter(item => item.type !== 'parent').map(item => item.option);\n\n // switch between selection and deselection behavior, ignores disabled options to prevent\n // getting stuck on one behavior when an option is disabled and its state cannot be changed\n const isAllChildrenSelected = (optionsArray: OptionDefinition[]) =>\n optionsArray.every(item => findOptionIndex(selectedOptions, item) > -1 || item.disabled);\n const intersection = (visibleOptions: OptionDefinition[], options: OptionDefinition[]) =>\n visibleOptions.filter(item => findOptionIndex(options, item) > -1 && !item.disabled);\n const union = (visibleOptions: OptionDefinition[], options: OptionDefinition[]) =>\n visibleOptions.filter(item => findOptionIndex(options, item) === -1).concat(options);\n const select = (options: OptionDefinition[], selectedOptions: OptionDefinition[]) => {\n return union(selectedOptions, options);\n };\n const unselect = (options: OptionDefinition[], selectedOptions: OptionDefinition[]) => {\n return selectedOptions.filter(option => findOptionIndex(options, option) === -1);\n };\n let newSelectedOptions = [...selectedOptions];\n\n if (isGroup(option)) {\n const visibleOptions = intersection([...option.options], filtered);\n newSelectedOptions = isAllChildrenSelected(visibleOptions)\n ? unselect(visibleOptions, newSelectedOptions)\n : select(visibleOptions, newSelectedOptions);\n } else {\n newSelectedOptions = isAllChildrenSelected([option])\n ? unselect([option], newSelectedOptions)\n : select([option], newSelectedOptions);\n }\n\n fireNonCancelableEvent(onChange, {\n selectedOptions: newSelectedOptions,\n });\n },\n [onChange, selectedOptions, filteredOptions]\n );\n\n const scrollToIndex = useRef<SelectListProps.SelectListRef>(null);\n const {\n isOpen,\n highlightType,\n highlightedOption,\n highlightedIndex,\n getTriggerProps,\n getDropdownProps,\n getFilterProps,\n getMenuProps,\n getOptionProps,\n highlightOption,\n announceSelected,\n } = useSelect({\n selectedOptions,\n updateSelectedOption,\n options: filteredOptions,\n filteringType,\n onFocus,\n onBlur,\n externalRef,\n keepOpen,\n fireLoadItems,\n setFilteringValue,\n useInteractiveGroups,\n statusType,\n embedded,\n });\n\n const wrapperOnKeyDown = useNativeSearch({\n isEnabled: filteringType === 'none' && isOpen,\n options: filteredOptions,\n highlightOption: highlightOption,\n highlightedOption: highlightedOption?.option,\n useInteractiveGroups,\n });\n\n const isEmpty = !options || options.length === 0;\n const isNoMatch = filteredOptions && filteredOptions.length === 0;\n const isFiltered =\n filteringType !== 'none' && filteringValue.length > 0 && filteredOptions && filteredOptions.length > 0;\n const filteredText = isFiltered ? filteringResultsText?.(matchesCount, totalCount) : undefined;\n const dropdownStatus = useDropdownStatus({\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n recoveryText,\n isEmpty,\n isNoMatch,\n noMatch,\n isFiltered,\n filteringResultsText: filteredText,\n onRecoveryClick: handleRecoveryClick,\n errorIconAriaLabel: errorIconAriaLabel,\n hasRecoveryCallback: !!onLoadItems,\n });\n\n const announcement = useAnnouncement({\n announceSelected,\n highlightedOption,\n getParent: option => parentMap.get(option)?.option as undefined | OptionGroup,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n const tokens: TokenGroupProps['items'] = selectedOptions.map(option => ({\n label: option.label,\n disabled: disabled || option.disabled,\n labelTag: option.labelTag,\n description: option.description,\n iconAlt: option.iconAlt,\n iconName: option.iconName,\n iconUrl: option.iconUrl,\n iconSvg: option.iconSvg,\n tags: option.tags,\n dismissLabel: i18n('deselectAriaLabel', deselectAriaLabel?.(option), format =>\n format({ option__label: option.label ?? '' })\n ),\n }));\n\n useEffect(() => {\n scrollToIndex.current?.(highlightedIndex);\n }, [highlightedIndex]);\n\n const dropdownOnMouseDown = (event: React.MouseEvent) => {\n const target = event.target as HTMLElement;\n\n if (target !== document.activeElement) {\n // prevent currently focused element from losing it\n event.preventDefault();\n }\n };\n\n const tokenOnDismiss: TokenGroupProps['onDismiss'] = ({ detail }) => {\n const optionToDeselect = selectedOptions[detail.itemIndex];\n updateSelectedOption(optionToDeselect);\n const targetRef = getTriggerProps().ref;\n if (targetRef.current) {\n targetRef.current.focus();\n }\n };\n\n return {\n isOpen,\n tokens,\n announcement,\n dropdownStatus,\n filteringValue,\n filteredOptions,\n highlightType,\n scrollToIndex,\n getFilterProps,\n getTriggerProps,\n getMenuProps: () => ({\n ...getMenuProps(),\n onLoadMore: handleLoadMore,\n ariaLabelledby: joinStrings(ariaLabelId, controlId),\n ariaDescribedby: dropdownStatus.content ? footerId : undefined,\n embedded,\n }),\n getOptionProps,\n getTokenProps: () => ({ onDismiss: tokenOnDismiss }),\n getDropdownProps: () => ({ ...getDropdownProps(), onMouseDown: dropdownOnMouseDown }),\n getWrapperProps: () => ({ onKeyDown: wrapperOnKeyDown }),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-multiselect.js","sourceRoot":"","sources":["../../../src/multiselect/use-multiselect.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAuB,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,oDAAoD,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,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,CAAC,WAAW,EAAE,SAAS,CAAC,EACnD,eAAe,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAC9D,QAAQ,IACR;QACF,cAAc;QACd,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;QACpD,gBAAgB,EAAE,GAAG,EAAE,CAAC,iCAAM,gBAAgB,EAAE,KAAE,WAAW,EAAE,mBAAmB,IAAG;QACrF,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;QACxD,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useCallback, useEffect, useMemo, useRef } from 'react';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context';\nimport { DropdownStatusProps, useDropdownStatus } from '../internal/components/dropdown-status';\nimport { DropdownOption, OptionDefinition, OptionGroup } from '../internal/components/option/interfaces';\nimport { isGroup } from '../internal/components/option/utils/filter-options';\nimport { prepareOptions } from '../internal/components/option/utils/prepare-options';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings';\nimport { SelectListProps } from '../select/parts/plain-list';\nimport { checkOptionValueField } from '../select/utils/check-option-value-field.js';\nimport { findOptionIndex } from '../select/utils/connect-options';\nimport { useAnnouncement } from '../select/utils/use-announcement';\nimport { useLoadItems } from '../select/utils/use-load-items';\nimport { useNativeSearch } from '../select/utils/use-native-search';\nimport { useSelect } from '../select/utils/use-select';\nimport { TokenGroupProps } from '../token-group/interfaces';\nimport { MultiselectProps } from './interfaces';\n\ntype UseMultiselectOptions = SomeRequired<\n Pick<\n MultiselectProps,\n | 'options'\n | 'selectedOptions'\n | 'filteringType'\n | 'filteringResultsText'\n | 'disabled'\n | 'noMatch'\n | 'renderHighlightedAriaLive'\n | 'deselectAriaLabel'\n | 'keepOpen'\n | 'onBlur'\n | 'onFocus'\n | 'onLoadItems'\n | 'onChange'\n | 'selectedAriaLabel'\n | 'enableSelectAll'\n | 'i18nStrings'\n > &\n DropdownStatusProps & {\n controlId?: string;\n ariaLabelId: string;\n footerId: string;\n filteringValue: string;\n setFilteringValue?: (value: string) => void;\n externalRef: React.Ref<MultiselectProps.Ref>;\n },\n 'options' | 'selectedOptions' | 'filteringType' | 'statusType' | 'keepOpen'\n> & { embedded?: boolean };\n\nexport function useMultiselect({\n options,\n filteringType,\n filteringResultsText,\n disabled,\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n noMatch,\n renderHighlightedAriaLive,\n selectedOptions,\n deselectAriaLabel,\n keepOpen,\n onBlur,\n onFocus,\n onLoadItems,\n onChange,\n controlId,\n ariaLabelId,\n footerId,\n filteringValue,\n setFilteringValue,\n externalRef,\n embedded,\n enableSelectAll,\n i18nStrings,\n ...restProps\n}: UseMultiselectOptions) {\n checkOptionValueField('Multiselect', 'options', options);\n\n const i18n = useInternalI18n('multiselect');\n const i18nCommon = useInternalI18n('select');\n const recoveryText = i18nCommon('recoveryText', restProps.recoveryText);\n const errorIconAriaLabel = i18nCommon('errorIconAriaLabel', restProps.errorIconAriaLabel);\n const selectedAriaLabel = i18nCommon('selectedAriaLabel', restProps.selectedAriaLabel);\n\n if (restProps.recoveryText && !onLoadItems) {\n warnOnce('Multiselect', '`onLoadItems` must be provided for `recoveryText` to be displayed.');\n }\n\n const { handleLoadMore, handleRecoveryClick, fireLoadItems } = useLoadItems({\n onLoadItems,\n options,\n statusType,\n });\n const useInteractiveGroups = true;\n const { flatOptions, filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(\n options,\n filteringType,\n filteringValue\n );\n\n const selectAllOption: DropdownOption = {\n type: 'select-all',\n afterHeader: filteringType !== 'none',\n option: { label: i18n('i18nStrings.selectAllText', i18nStrings?.selectAllText) },\n };\n\n const visibleOptions =\n enableSelectAll && filteredOptions.length ? [selectAllOption, ...filteredOptions] : filteredOptions;\n\n // Includes visible and non-visible (filtered out) options\n const allNonParentOptions = flatOptions.filter(item => item.type !== 'parent').map(option => option.option);\n\n const filteredNonParentOptions = filteredOptions.filter(item => item.type !== 'parent').map(item => item.option);\n\n const selectedValues = useMemo(() => new Set(selectedOptions.map(option => option.value)), [selectedOptions]);\n\n const isSomeSelected = selectedOptions.length > 0;\n const isAllVisibleSelectableSelected =\n isSomeSelected && filteredNonParentOptions.every(option => option.disabled || selectedValues.has(option.value));\n const isAllSelected = allNonParentOptions.every(option => selectedValues.has(option.value));\n\n const toggleAll = () => {\n const filteredNonParentOptionValues = new Set(filteredNonParentOptions.map(option => option.value));\n fireNonCancelableEvent(onChange, {\n selectedOptions: isAllVisibleSelectableSelected\n ? selectedOptions.filter(option => !filteredNonParentOptionValues.has(option.value))\n : allNonParentOptions.filter(\n ({ disabled, value }) =>\n selectedValues.has(value) || (!disabled && filteredNonParentOptionValues.has(value))\n ),\n });\n };\n\n const updateSelectedOption = useCallback(\n (option: OptionDefinition | OptionGroup) => {\n // switch between selection and deselection behavior, ignores disabled options to prevent\n // getting stuck on one behavior when an option is disabled and its state cannot be changed\n const isAllChildrenSelected = (optionsArray: OptionDefinition[]) =>\n optionsArray.every(item => findOptionIndex(selectedOptions, item) > -1 || item.disabled);\n const intersection = (visibleOptions: OptionDefinition[], options: OptionDefinition[]) =>\n visibleOptions.filter(item => findOptionIndex(options, item) > -1 && !item.disabled);\n const union = (visibleOptions: OptionDefinition[], options: OptionDefinition[]) =>\n visibleOptions.filter(item => findOptionIndex(options, item) === -1).concat(options);\n const select = (options: OptionDefinition[], selectedOptions: OptionDefinition[]) => {\n return union(selectedOptions, options);\n };\n const unselect = (options: OptionDefinition[], selectedOptions: OptionDefinition[]) => {\n return selectedOptions.filter(option => findOptionIndex(options, option) === -1);\n };\n let newSelectedOptions = [...selectedOptions];\n\n if (isGroup(option)) {\n const visibleOptions = intersection([...option.options], filteredNonParentOptions);\n newSelectedOptions = isAllChildrenSelected(visibleOptions)\n ? unselect(visibleOptions, newSelectedOptions)\n : select(visibleOptions, newSelectedOptions);\n } else {\n newSelectedOptions = isAllChildrenSelected([option])\n ? unselect([option], newSelectedOptions)\n : select([option], newSelectedOptions);\n }\n\n fireNonCancelableEvent(onChange, {\n selectedOptions: newSelectedOptions,\n });\n },\n [selectedOptions, onChange, filteredNonParentOptions]\n );\n\n const scrollToIndex = useRef<SelectListProps.SelectListRef>(null);\n const {\n isOpen,\n highlightType,\n highlightedOption,\n highlightedIndex,\n getTriggerProps,\n getDropdownProps,\n getFilterProps,\n getMenuProps,\n getOptionProps,\n highlightOption,\n announceSelected,\n } = useSelect({\n selectedOptions,\n updateSelectedOption,\n options: visibleOptions,\n filteringType,\n onFocus,\n onBlur,\n externalRef,\n keepOpen,\n fireLoadItems,\n setFilteringValue,\n useInteractiveGroups,\n statusType,\n embedded,\n isAllSelected,\n isSomeSelected,\n toggleAll,\n });\n\n const wrapperOnKeyDown = useNativeSearch({\n isEnabled: filteringType === 'none' && isOpen,\n options: visibleOptions,\n highlightOption: highlightOption,\n highlightedOption: highlightedOption?.option,\n useInteractiveGroups,\n });\n\n const isEmpty = !options || options.length === 0;\n const isNoMatch = filteredOptions && filteredOptions.length === 0;\n const isFiltered =\n filteringType !== 'none' && filteringValue.length > 0 && filteredOptions && filteredOptions.length > 0;\n const filteredText = isFiltered ? filteringResultsText?.(matchesCount, totalCount) : undefined;\n const dropdownStatus = useDropdownStatus({\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n recoveryText,\n isEmpty,\n isNoMatch,\n noMatch,\n isFiltered,\n filteringResultsText: filteredText,\n onRecoveryClick: handleRecoveryClick,\n errorIconAriaLabel: errorIconAriaLabel,\n hasRecoveryCallback: !!onLoadItems,\n });\n\n const announcement = useAnnouncement({\n announceSelected,\n highlightedOption,\n getParent: option => parentMap.get(option)?.option as undefined | OptionGroup,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n const tokens: TokenGroupProps['items'] = selectedOptions.map(option => ({\n label: option.label,\n disabled: disabled || option.disabled,\n labelTag: option.labelTag,\n description: option.description,\n iconAlt: option.iconAlt,\n iconName: option.iconName,\n iconUrl: option.iconUrl,\n iconSvg: option.iconSvg,\n tags: option.tags,\n dismissLabel: i18n('deselectAriaLabel', deselectAriaLabel?.(option), format =>\n format({ option__label: option.label ?? '' })\n ),\n }));\n\n useEffect(() => {\n scrollToIndex.current?.(highlightedIndex);\n }, [highlightedIndex]);\n\n const dropdownOnMouseDown = (event: React.MouseEvent) => {\n const target = event.target as HTMLElement;\n\n if (target !== document.activeElement) {\n // prevent currently focused element from losing it\n event.preventDefault();\n }\n };\n\n const tokenOnDismiss: TokenGroupProps['onDismiss'] = ({ detail }) => {\n const optionToDeselect = selectedOptions[detail.itemIndex];\n updateSelectedOption(optionToDeselect);\n const targetRef = getTriggerProps().ref;\n if (targetRef.current) {\n targetRef.current.focus();\n }\n };\n\n return {\n isOpen,\n tokens,\n announcement,\n dropdownStatus,\n filteringValue,\n filteredOptions: visibleOptions,\n highlightType,\n scrollToIndex,\n getFilterProps,\n getTriggerProps,\n getMenuProps: () => ({\n ...getMenuProps(),\n onLoadMore: handleLoadMore,\n ariaLabelledby: joinStrings(ariaLabelId, controlId),\n ariaDescribedby: dropdownStatus.content ? footerId : undefined,\n embedded,\n }),\n getOptionProps,\n getTokenProps: () => ({ onDismiss: tokenOnDismiss }),\n getDropdownProps: () => ({ ...getDropdownProps(), onMouseDown: dropdownOnMouseDown }),\n getWrapperProps: () => ({ onKeyDown: wrapperOnKeyDown }),\n highlightedIndex,\n };\n}\n"]}
|
|
@@ -65,7 +65,7 @@ const InternalSelect = React.forwardRef((_a, externalRef) => {
|
|
|
65
65
|
statusType,
|
|
66
66
|
});
|
|
67
67
|
const handleNativeSearch = useNativeSearch({
|
|
68
|
-
isEnabled: filteringType === 'none',
|
|
68
|
+
isEnabled: filteringType === 'none' && !readOnly,
|
|
69
69
|
options: filteredOptions,
|
|
70
70
|
highlightOption: !isOpen ? selectOption : highlightOption,
|
|
71
71
|
highlightedOption: !isOpen ? selectedOption : highlightedOption === null || highlightedOption === void 0 ? void 0 : highlightedOption.option,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/select/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,eAAe,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE,OAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,OAAO,SAA8B,MAAM,oBAAoB,CAAC;AAChE,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/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Q,CAAC,CAAC,CAAC,CACxB,oBAAC,cAAc,IAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,GAAI,CAClF,CAAC,CAAC,CAAC,IAAI,EAEV,gBAAgB,EAAE,gBAAgB;YAElC,oBAAC,aAAa,IACZ,UAAU,EACR,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CACzB,oBAAC,cAAc,IAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,GAAI,CAClF,CAAC,CAAC,CAAC,IAAI,EAEV,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,aAAa,EAClB,iBAAiB,EAAE,cAAc,CAAC,OAAO,KAAK,IAAI,EAClD,mBAAmB,EAAE,YAAY,EACjC,aAAa,EAAE,aAAa,GAC5B,CACO;QACX,6BAAK,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,iBAAiB,IACrC,SAAS,IAAI,eAAe,CACzB,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context.js';\nimport { getBaseProps } from '../internal/base-component';\nimport Dropdown from '../internal/components/dropdown';\nimport DropdownFooter from '../internal/components/dropdown-footer';\nimport { useDropdownStatus } from '../internal/components/dropdown-status';\nimport { OptionGroup } from '../internal/components/option/interfaces.js';\nimport { prepareOptions } from '../internal/components/option/utils/prepare-options';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings/join-strings.js';\nimport { SelectProps } from './interfaces';\nimport Filter from './parts/filter';\nimport PlainList, { SelectListProps } from './parts/plain-list';\nimport Trigger from './parts/trigger';\nimport VirtualList from './parts/virtual-list';\nimport { checkOptionValueField } from './utils/check-option-value-field';\nimport { useAnnouncement } from './utils/use-announcement';\nimport { useLoadItems } from './utils/use-load-items';\nimport { useNativeSearch } from './utils/use-native-search';\nimport { useSelect } from './utils/use-select';\n\nimport styles from './styles.css.js';\n\nexport interface InternalSelectProps extends SomeRequired<SelectProps, 'options'>, InternalBaseComponentProps {\n __inFilteringToken?: 'root' | 'nested';\n}\n\nconst InternalSelect = React.forwardRef(\n (\n {\n options,\n filteringType = 'none',\n filteringPlaceholder,\n filteringAriaLabel,\n filteringClearAriaLabel,\n filteringResultsText,\n inlineLabelText,\n ariaRequired,\n placeholder,\n disabled,\n readOnly,\n ariaLabel,\n statusType = 'finished',\n empty,\n loadingText,\n finishedText,\n errorText,\n noMatch,\n triggerVariant = 'label',\n renderHighlightedAriaLive,\n selectedOption,\n onBlur,\n onFocus,\n onLoadItems,\n onChange,\n virtualScroll,\n expandToViewport,\n autoFocus,\n __inFilteringToken,\n __internalRootRef = null,\n ...restProps\n }: InternalSelectProps,\n externalRef: React.Ref<SelectProps.Ref>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n\n const i18n = useInternalI18n('select');\n const errorIconAriaLabel = i18n('errorIconAriaLabel', restProps.errorIconAriaLabel);\n const selectedAriaLabel = i18n('selectedAriaLabel', restProps.selectedAriaLabel);\n const recoveryText = i18n('recoveryText', restProps.recoveryText);\n\n if (restProps.recoveryText && !onLoadItems) {\n warnOnce('Select', '`onLoadItems` must be provided for `recoveryText` to be displayed.');\n }\n\n const { handleLoadMore, handleRecoveryClick, fireLoadItems } = useLoadItems({\n onLoadItems,\n options,\n statusType,\n });\n\n checkControlled('Select', 'selectedOption', selectedOption, 'onChange', onChange);\n\n checkOptionValueField('Select', 'options', options);\n\n const [filteringValue, setFilteringValue] = useState('');\n\n const { filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(\n options,\n filteringType,\n filteringValue\n );\n\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n\n const selfControlId = useUniqueId('trigger');\n const controlId = formFieldContext.controlId ?? selfControlId;\n\n const scrollToIndex = useRef<SelectListProps.SelectListRef>(null);\n const {\n isOpen,\n highlightType,\n highlightedOption,\n highlightedIndex,\n getTriggerProps,\n getDropdownProps,\n getFilterProps,\n getMenuProps,\n getOptionProps,\n highlightOption,\n selectOption,\n announceSelected,\n } = useSelect({\n selectedOptions: selectedOption ? [selectedOption] : [],\n updateSelectedOption: option => fireNonCancelableEvent(onChange, { selectedOption: option }),\n options: filteredOptions,\n filteringType,\n onBlur,\n onFocus,\n externalRef,\n fireLoadItems,\n setFilteringValue,\n statusType,\n });\n\n const handleNativeSearch = useNativeSearch({\n isEnabled: filteringType === 'none',\n options: filteredOptions,\n highlightOption: !isOpen ? selectOption : highlightOption,\n highlightedOption: !isOpen ? selectedOption : highlightedOption?.option,\n });\n\n const selectAriaLabelId = useUniqueId('select-arialabel-');\n const footerId = useUniqueId('footer');\n\n useEffect(() => {\n scrollToIndex.current?.(highlightedIndex);\n }, [highlightedIndex]);\n\n const filter = (\n <Filter\n clearAriaLabel={filteringClearAriaLabel}\n filteringType={filteringType}\n placeholder={filteringPlaceholder}\n ariaLabel={filteringAriaLabel}\n ariaRequired={ariaRequired}\n value={filteringValue}\n {...getFilterProps()}\n />\n );\n\n const trigger = (\n <Trigger\n ref={triggerRef}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readOnly}\n triggerVariant={triggerVariant}\n triggerProps={getTriggerProps(disabled, autoFocus)}\n selectedOption={selectedOption}\n isOpen={isOpen}\n inFilteringToken={__inFilteringToken}\n inlineLabelText={inlineLabelText}\n {...formFieldContext}\n controlId={controlId}\n ariaLabelledby={joinStrings(formFieldContext.ariaLabelledby, selectAriaLabelId)}\n />\n );\n\n const isEmpty = !options || options.length === 0;\n const isNoMatch = filteredOptions && filteredOptions.length === 0;\n const isFiltered =\n filteringType !== 'none' && filteringValue.length > 0 && filteredOptions && filteredOptions.length > 0;\n const filteredText = isFiltered ? filteringResultsText?.(matchesCount, totalCount) : undefined;\n\n const dropdownStatus = useDropdownStatus({\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n recoveryText,\n isEmpty,\n isNoMatch,\n noMatch,\n isFiltered,\n filteringResultsText: filteredText,\n errorIconAriaLabel,\n onRecoveryClick: handleRecoveryClick,\n hasRecoveryCallback: !!onLoadItems,\n });\n\n const menuProps = {\n ...getMenuProps(),\n onLoadMore: handleLoadMore,\n ariaLabelledby: joinStrings(selectAriaLabelId, controlId),\n ariaDescribedby: dropdownStatus.content ? footerId : undefined,\n };\n\n const announcement = useAnnouncement({\n announceSelected,\n highlightedOption,\n getParent: option => parentMap.get(option)?.option as undefined | OptionGroup,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n const ListComponent = virtualScroll ? VirtualList : PlainList;\n\n const handleMouseDown = (event: React.MouseEvent) => {\n const target = event.target as HTMLElement;\n\n if (target !== document.activeElement) {\n // prevent currently focused element from losing it\n event.preventDefault();\n }\n };\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n const dropdownProps = getDropdownProps();\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(styles.root, baseProps.className)}\n onKeyDown={handleNativeSearch}\n >\n <Dropdown\n {...dropdownProps}\n ariaLabelledby={dropdownProps.dropdownContentRole ? joinStrings(selectAriaLabelId, controlId) : undefined}\n ariaDescribedby={\n dropdownProps.dropdownContentRole ? (dropdownStatus.content ? footerId : undefined) : undefined\n }\n open={isOpen}\n stretchTriggerHeight={!!__inFilteringToken}\n stretchBeyondTriggerWidth={true}\n trigger={trigger}\n header={filter}\n onMouseDown={handleMouseDown}\n footer={\n dropdownStatus.isSticky ? (\n <DropdownFooter content={isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n expandToViewport={expandToViewport}\n >\n <ListComponent\n listBottom={\n !dropdownStatus.isSticky ? (\n <DropdownFooter content={isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n menuProps={menuProps}\n getOptionProps={getOptionProps}\n filteredOptions={filteredOptions}\n filteringValue={filteringValue}\n ref={scrollToIndex}\n hasDropdownStatus={dropdownStatus.content !== null}\n screenReaderContent={announcement}\n highlightType={highlightType}\n />\n </Dropdown>\n <div hidden={true} id={selectAriaLabelId}>\n {ariaLabel || inlineLabelText}\n </div>\n </div>\n );\n }\n);\n\nexport default InternalSelect;\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/select/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAC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rC,SAAS,IAAI,eAAe,CACzB,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useInternalI18n } from '../i18n/context.js';\nimport { getBaseProps } from '../internal/base-component';\nimport Dropdown from '../internal/components/dropdown';\nimport DropdownFooter from '../internal/components/dropdown-footer';\nimport { useDropdownStatus } from '../internal/components/dropdown-status';\nimport { OptionGroup } from '../internal/components/option/interfaces.js';\nimport { prepareOptions } from '../internal/components/option/utils/prepare-options';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { SomeRequired } from '../internal/types';\nimport { joinStrings } from '../internal/utils/strings/join-strings.js';\nimport { SelectProps } from './interfaces';\nimport Filter from './parts/filter';\nimport PlainList, { SelectListProps } from './parts/plain-list';\nimport Trigger from './parts/trigger';\nimport VirtualList from './parts/virtual-list';\nimport { checkOptionValueField } from './utils/check-option-value-field';\nimport { useAnnouncement } from './utils/use-announcement';\nimport { useLoadItems } from './utils/use-load-items';\nimport { useNativeSearch } from './utils/use-native-search';\nimport { useSelect } from './utils/use-select';\n\nimport styles from './styles.css.js';\n\nexport interface InternalSelectProps extends SomeRequired<SelectProps, 'options'>, InternalBaseComponentProps {\n __inFilteringToken?: 'root' | 'nested';\n}\n\nconst InternalSelect = React.forwardRef(\n (\n {\n options,\n filteringType = 'none',\n filteringPlaceholder,\n filteringAriaLabel,\n filteringClearAriaLabel,\n filteringResultsText,\n inlineLabelText,\n ariaRequired,\n placeholder,\n disabled,\n readOnly,\n ariaLabel,\n statusType = 'finished',\n empty,\n loadingText,\n finishedText,\n errorText,\n noMatch,\n triggerVariant = 'label',\n renderHighlightedAriaLive,\n selectedOption,\n onBlur,\n onFocus,\n onLoadItems,\n onChange,\n virtualScroll,\n expandToViewport,\n autoFocus,\n __inFilteringToken,\n __internalRootRef = null,\n ...restProps\n }: InternalSelectProps,\n externalRef: React.Ref<SelectProps.Ref>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n\n const i18n = useInternalI18n('select');\n const errorIconAriaLabel = i18n('errorIconAriaLabel', restProps.errorIconAriaLabel);\n const selectedAriaLabel = i18n('selectedAriaLabel', restProps.selectedAriaLabel);\n const recoveryText = i18n('recoveryText', restProps.recoveryText);\n\n if (restProps.recoveryText && !onLoadItems) {\n warnOnce('Select', '`onLoadItems` must be provided for `recoveryText` to be displayed.');\n }\n\n const { handleLoadMore, handleRecoveryClick, fireLoadItems } = useLoadItems({\n onLoadItems,\n options,\n statusType,\n });\n\n checkControlled('Select', 'selectedOption', selectedOption, 'onChange', onChange);\n\n checkOptionValueField('Select', 'options', options);\n\n const [filteringValue, setFilteringValue] = useState('');\n\n const { filteredOptions, parentMap, totalCount, matchesCount } = prepareOptions(\n options,\n filteringType,\n filteringValue\n );\n\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n\n const selfControlId = useUniqueId('trigger');\n const controlId = formFieldContext.controlId ?? selfControlId;\n\n const scrollToIndex = useRef<SelectListProps.SelectListRef>(null);\n const {\n isOpen,\n highlightType,\n highlightedOption,\n highlightedIndex,\n getTriggerProps,\n getDropdownProps,\n getFilterProps,\n getMenuProps,\n getOptionProps,\n highlightOption,\n selectOption,\n announceSelected,\n } = useSelect({\n selectedOptions: selectedOption ? [selectedOption] : [],\n updateSelectedOption: option => fireNonCancelableEvent(onChange, { selectedOption: option }),\n options: filteredOptions,\n filteringType,\n onBlur,\n onFocus,\n externalRef,\n fireLoadItems,\n setFilteringValue,\n statusType,\n });\n\n const handleNativeSearch = useNativeSearch({\n isEnabled: filteringType === 'none' && !readOnly,\n options: filteredOptions,\n highlightOption: !isOpen ? selectOption : highlightOption,\n highlightedOption: !isOpen ? selectedOption : highlightedOption?.option,\n });\n\n const selectAriaLabelId = useUniqueId('select-arialabel-');\n const footerId = useUniqueId('footer');\n\n useEffect(() => {\n scrollToIndex.current?.(highlightedIndex);\n }, [highlightedIndex]);\n\n const filter = (\n <Filter\n clearAriaLabel={filteringClearAriaLabel}\n filteringType={filteringType}\n placeholder={filteringPlaceholder}\n ariaLabel={filteringAriaLabel}\n ariaRequired={ariaRequired}\n value={filteringValue}\n {...getFilterProps()}\n />\n );\n\n const trigger = (\n <Trigger\n ref={triggerRef}\n placeholder={placeholder}\n disabled={disabled}\n readOnly={readOnly}\n triggerVariant={triggerVariant}\n triggerProps={getTriggerProps(disabled, autoFocus)}\n selectedOption={selectedOption}\n isOpen={isOpen}\n inFilteringToken={__inFilteringToken}\n inlineLabelText={inlineLabelText}\n {...formFieldContext}\n controlId={controlId}\n ariaLabelledby={joinStrings(formFieldContext.ariaLabelledby, selectAriaLabelId)}\n />\n );\n\n const isEmpty = !options || options.length === 0;\n const isNoMatch = filteredOptions && filteredOptions.length === 0;\n const isFiltered =\n filteringType !== 'none' && filteringValue.length > 0 && filteredOptions && filteredOptions.length > 0;\n const filteredText = isFiltered ? filteringResultsText?.(matchesCount, totalCount) : undefined;\n\n const dropdownStatus = useDropdownStatus({\n statusType,\n empty,\n loadingText,\n finishedText,\n errorText,\n recoveryText,\n isEmpty,\n isNoMatch,\n noMatch,\n isFiltered,\n filteringResultsText: filteredText,\n errorIconAriaLabel,\n onRecoveryClick: handleRecoveryClick,\n hasRecoveryCallback: !!onLoadItems,\n });\n\n const menuProps = {\n ...getMenuProps(),\n onLoadMore: handleLoadMore,\n ariaLabelledby: joinStrings(selectAriaLabelId, controlId),\n ariaDescribedby: dropdownStatus.content ? footerId : undefined,\n };\n\n const announcement = useAnnouncement({\n announceSelected,\n highlightedOption,\n getParent: option => parentMap.get(option)?.option as undefined | OptionGroup,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n const ListComponent = virtualScroll ? VirtualList : PlainList;\n\n const handleMouseDown = (event: React.MouseEvent) => {\n const target = event.target as HTMLElement;\n\n if (target !== document.activeElement) {\n // prevent currently focused element from losing it\n event.preventDefault();\n }\n };\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n const dropdownProps = getDropdownProps();\n\n return (\n <div\n {...baseProps}\n ref={mergedRef}\n className={clsx(styles.root, baseProps.className)}\n onKeyDown={handleNativeSearch}\n >\n <Dropdown\n {...dropdownProps}\n ariaLabelledby={dropdownProps.dropdownContentRole ? joinStrings(selectAriaLabelId, controlId) : undefined}\n ariaDescribedby={\n dropdownProps.dropdownContentRole ? (dropdownStatus.content ? footerId : undefined) : undefined\n }\n open={isOpen}\n stretchTriggerHeight={!!__inFilteringToken}\n stretchBeyondTriggerWidth={true}\n trigger={trigger}\n header={filter}\n onMouseDown={handleMouseDown}\n footer={\n dropdownStatus.isSticky ? (\n <DropdownFooter content={isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n expandToViewport={expandToViewport}\n >\n <ListComponent\n listBottom={\n !dropdownStatus.isSticky ? (\n <DropdownFooter content={isOpen ? dropdownStatus.content : null} id={footerId} />\n ) : null\n }\n menuProps={menuProps}\n getOptionProps={getOptionProps}\n filteredOptions={filteredOptions}\n filteringValue={filteringValue}\n ref={scrollToIndex}\n hasDropdownStatus={dropdownStatus.content !== null}\n screenReaderContent={announcement}\n highlightType={highlightType}\n />\n </Dropdown>\n <div hidden={true} id={selectAriaLabelId}>\n {ariaLabel || inlineLabelText}\n </div>\n </div>\n );\n }\n);\n\nexport default InternalSelect;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/common.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/select/parts/common.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nexport const fallbackItemHeight = 31;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiselect-item.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/multiselect-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAU3D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,UAAU,oBAAqB,SAAQ,SAAS;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;;
|
|
1
|
+
{"version":3,"file":"multiselect-item.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/multiselect-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAU3D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,UAAU,oBAAqB,SAAQ,SAAS;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;;AAwGD,wBAA6D"}
|
|
@@ -15,6 +15,7 @@ const MultiSelectItem = (_a, ref) => {
|
|
|
15
15
|
const baseProps = getBaseProps(restProps);
|
|
16
16
|
const isParent = option.type === 'parent';
|
|
17
17
|
const isChild = option.type === 'child';
|
|
18
|
+
const isSelectAll = option.type === 'select-all';
|
|
18
19
|
const wrappedOption = option.option;
|
|
19
20
|
const disabled = option.disabled || wrappedOption.disabled;
|
|
20
21
|
const disabledReason = disabled && (option.disabledReason || wrappedOption.disabledReason)
|
|
@@ -26,10 +27,10 @@ const MultiSelectItem = (_a, ref) => {
|
|
|
26
27
|
const { descriptionId, descriptionEl } = useHiddenDescription(disabledReason);
|
|
27
28
|
const [canShowTooltip, setCanShowTooltip] = useState(true);
|
|
28
29
|
useEffect(() => setCanShowTooltip(true), [highlighted]);
|
|
29
|
-
return (React.createElement(SelectableItem, Object.assign({ ariaChecked: isParent && indeterminate ? 'mixed' : Boolean(selected), selected: selected, isNextSelected: isNextSelected, highlighted: highlighted, disabled: disabled, isParent: isParent, isChild: isChild, highlightType: highlightType, ref: useMergeRefs(ref, internalRef), virtualPosition: virtualPosition, padBottom: padBottom, useInteractiveGroups: true, screenReaderContent: screenReaderContent, ariaPosinset: ariaPosinset, ariaSetsize: ariaSetsize, ariaDescribedby: isDisabledWithReason ? descriptionId : '', value: option.option.value, afterHeader: option.afterHeader, withScrollbar: withScrollbar, sticky: sticky }, baseProps),
|
|
30
|
+
return (React.createElement(SelectableItem, Object.assign({ ariaChecked: isParent && indeterminate ? 'mixed' : Boolean(selected), selected: selected, isNextSelected: isNextSelected, highlighted: highlighted, disabled: disabled, isParent: isParent, isChild: isChild, isSelectAll: isSelectAll, highlightType: highlightType, ref: useMergeRefs(ref, internalRef), virtualPosition: virtualPosition, padBottom: padBottom, useInteractiveGroups: true, screenReaderContent: screenReaderContent, ariaPosinset: ariaPosinset, ariaSetsize: ariaSetsize, ariaDescribedby: isDisabledWithReason ? descriptionId : '', value: option.option.value, afterHeader: option.afterHeader, withScrollbar: withScrollbar, sticky: sticky }, baseProps),
|
|
30
31
|
React.createElement("div", { className: className },
|
|
31
32
|
hasCheckbox && (React.createElement("div", { className: styles.checkbox },
|
|
32
|
-
React.createElement(CheckboxIcon, { checked: selected, indeterminate: isParent && indeterminate, disabled:
|
|
33
|
+
React.createElement(CheckboxIcon, { checked: selected, indeterminate: (isParent || isSelectAll) && indeterminate, disabled: disabled }))),
|
|
33
34
|
React.createElement(Option, { option: Object.assign(Object.assign({}, wrappedOption), { disabled }), highlightedOption: highlighted, selectedOption: selected, highlightText: filteringValue, isGroupOption: isParent })),
|
|
34
35
|
isDisabledWithReason && (React.createElement(React.Fragment, null,
|
|
35
36
|
descriptionEl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiselect-item.js","sourceRoot":"","sources":["../../../../src/select/parts/multiselect-item.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,YAAY,MAAM,yCAAyC,CAAC;AACnE,OAAO,MAAM,MAAM,kCAAkC,CAAC;AAEtD,OAAO,cAAc,MAAM,2CAA2C,CAAC;AACvE,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,oBAAoB,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAGnE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAKrC,MAAM,eAAe,GAAG,CACtB,EAiBuB,EACvB,GAA8B,EAC9B,EAAE;QAnBF,EACE,MAAM,EACN,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,MAAM,OAEe,EADlB,SAAS,cAhBd,2OAiBC,CADa;IAId,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAE1C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;IAC1C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC;IACxC,MAAM,aAAa,GAAqB,MAAM,CAAC,MAAM,CAAC;IACtD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAA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EAAE,MAAM,CAAC,yBAAyB,CAAC,EAC5C,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,cAAe,EACtB,QAAQ,EAAC,OAAO,EAChB,gBAAgB,EAAE,IAAI,EACtB,SAAS,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,GACzC,CACH,CACA,CACJ,CACc,CAClB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport { getBaseProps } from '../../internal/base-component';\nimport CheckboxIcon from '../../internal/components/checkbox-icon';\nimport Option from '../../internal/components/option';\nimport { OptionDefinition } from '../../internal/components/option/interfaces';\nimport SelectableItem from '../../internal/components/selectable-item';\nimport Tooltip from '../../internal/components/tooltip';\nimport useHiddenDescription from '../../internal/hooks/use-hidden-description';\nimport { useMergeRefs } from '../../internal/hooks/use-merge-refs';\nimport { ItemProps } from './item';\n\nimport styles from './styles.css.js';\ninterface MultiselectItemProps extends ItemProps {\n indeterminate?: boolean;\n}\n\nconst MultiSelectItem = (\n {\n option,\n highlighted,\n selected,\n filteringValue,\n hasCheckbox,\n virtualPosition,\n padBottom,\n isNextSelected,\n indeterminate,\n screenReaderContent,\n ariaPosinset,\n ariaSetsize,\n highlightType,\n withScrollbar,\n sticky,\n ...restProps\n }: MultiselectItemProps,\n ref: React.Ref<HTMLDivElement>\n) => {\n const baseProps = getBaseProps(restProps);\n\n const isParent = option.type === 'parent';\n const isChild = option.type === 'child';\n const isSelectAll = option.type === 'select-all';\n const wrappedOption: OptionDefinition = option.option;\n const disabled = option.disabled || wrappedOption.disabled;\n const disabledReason =\n disabled && (option.disabledReason || wrappedOption.disabledReason)\n ? option.disabledReason || wrappedOption.disabledReason\n : '';\n const isDisabledWithReason = !!disabledReason;\n const internalRef = useRef<HTMLDivElement>(null);\n const className = styles.item;\n\n const { descriptionId, descriptionEl } = useHiddenDescription(disabledReason);\n\n const [canShowTooltip, setCanShowTooltip] = useState(true);\n useEffect(() => setCanShowTooltip(true), [highlighted]);\n return (\n <SelectableItem\n ariaChecked={isParent && indeterminate ? 'mixed' : Boolean(selected)}\n selected={selected}\n isNextSelected={isNextSelected}\n highlighted={highlighted}\n disabled={disabled}\n isParent={isParent}\n isChild={isChild}\n isSelectAll={isSelectAll}\n highlightType={highlightType}\n ref={useMergeRefs(ref, internalRef)}\n virtualPosition={virtualPosition}\n padBottom={padBottom}\n useInteractiveGroups={true}\n screenReaderContent={screenReaderContent}\n ariaPosinset={ariaPosinset}\n ariaSetsize={ariaSetsize}\n ariaDescribedby={isDisabledWithReason ? descriptionId : ''}\n value={option.option.value}\n afterHeader={option.afterHeader}\n withScrollbar={withScrollbar}\n sticky={sticky}\n {...baseProps}\n >\n <div className={className}>\n {hasCheckbox && (\n <div className={styles.checkbox}>\n <CheckboxIcon\n checked={selected}\n indeterminate={(isParent || isSelectAll) && indeterminate}\n disabled={disabled}\n />\n </div>\n )}\n <Option\n option={{ ...wrappedOption, disabled }}\n highlightedOption={highlighted}\n selectedOption={selected}\n highlightText={filteringValue}\n isGroupOption={isParent}\n />\n </div>\n {isDisabledWithReason && (\n <>\n {descriptionEl}\n {highlighted && canShowTooltip && (\n <Tooltip\n className={styles['disabled-reason-tooltip']}\n trackRef={internalRef}\n value={disabledReason!}\n position=\"right\"\n hideOnOverscroll={true}\n onDismiss={() => setCanShowTooltip(false)}\n />\n )}\n </>\n )}\n </SelectableItem>\n );\n};\n\nexport default React.memo(React.forwardRef(MultiSelectItem));\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-list.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/plain-list.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"plain-list.d.ts","sourceRoot":"","sources":["../../../../src/select/parts/plain-list.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAIjF,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,mEAAmE,CAAC;AAIlG,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKhE,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,yBAAiB,eAAe,CAAC;IAC/B,KAAY,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD;;AA0ED,wBAAqC"}
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
3
|
+
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
4
4
|
import { useContainerQuery } from '@cloudscape-design/component-toolkit';
|
|
5
5
|
import OptionsList from '../../internal/components/options-list';
|
|
6
6
|
import { useMergeRefs } from '../../internal/hooks/use-merge-refs';
|
|
7
|
-
import { scrollElementIntoView } from '../../internal/utils/scrollable-containers';
|
|
8
7
|
import { renderOptions } from '../utils/render-options';
|
|
8
|
+
import scrollToIndex from '../utils/scroll-to-index';
|
|
9
|
+
import { fallbackItemHeight } from './common';
|
|
9
10
|
import styles from './styles.css.js';
|
|
10
11
|
const PlainList = ({ menuProps, getOptionProps, filteredOptions, filteringValue, highlightType, checkboxes, hasDropdownStatus, listBottom, useInteractiveGroups, screenReaderContent, firstOptionSticky, }, ref) => {
|
|
11
|
-
const
|
|
12
|
+
const stickyOptionRef = useRef(null);
|
|
13
|
+
const [stickyOptionBlockSize, setStickyOptionBlockSize] = useState(firstOptionSticky ? fallbackItemHeight : 0);
|
|
14
|
+
const [width, menuMeasureRef] = useContainerQuery(rect => {
|
|
15
|
+
if (stickyOptionRef.current) {
|
|
16
|
+
// Cannot use container query on the sticky option individually because it is not rendered until the dropdown is open.
|
|
17
|
+
// Not expecting the sticky option to change size without the dropdown also changing size.
|
|
18
|
+
// The effects of using the sticky option block size to set the menu scroll padding are covered by integration tests.
|
|
19
|
+
// istanbul ignore next
|
|
20
|
+
setStickyOptionBlockSize(stickyOptionRef.current.clientHeight);
|
|
21
|
+
}
|
|
22
|
+
return { inner: rect.contentBoxWidth, outer: rect.borderBoxWidth };
|
|
23
|
+
});
|
|
12
24
|
const menuRef = menuProps.ref;
|
|
13
25
|
const mergedRef = useMergeRefs(menuMeasureRef, menuRef);
|
|
14
26
|
useImperativeHandle(ref, () => (index) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// In edge case dropdown can be very small, scrolling can cause side effect AWSUI-60318
|
|
19
|
-
if (((_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight) !== undefined && ((_c = menuRef.current) === null || _c === void 0 ? void 0 : _c.clientHeight) > 15) {
|
|
20
|
-
/* istanbul ignore next: clientHeight always returns 0 in JSDOM, the line is covered by integ tests */
|
|
21
|
-
scrollElementIntoView(item);
|
|
22
|
-
}
|
|
27
|
+
const isSticky = firstOptionSticky && index === 0;
|
|
28
|
+
if (highlightType.moveFocus && menuRef.current && !isSticky) {
|
|
29
|
+
scrollToIndex({ index, menuEl: menuRef.current });
|
|
23
30
|
}
|
|
24
|
-
}, [highlightType, menuRef]);
|
|
31
|
+
}, [firstOptionSticky, highlightType.moveFocus, menuRef]);
|
|
25
32
|
const withScrollbar = !!width && width.inner < width.outer;
|
|
26
|
-
return (React.createElement(OptionsList, Object.assign({}, menuProps, { ref: mergedRef }),
|
|
33
|
+
return (React.createElement(OptionsList, Object.assign({}, menuProps, { ref: mergedRef, stickyItemBlockSize: stickyOptionBlockSize }),
|
|
27
34
|
renderOptions({
|
|
28
35
|
options: filteredOptions,
|
|
29
36
|
getOptionProps,
|
|
@@ -33,8 +40,9 @@ const PlainList = ({ menuProps, getOptionProps, filteredOptions, filteringValue,
|
|
|
33
40
|
hasDropdownStatus,
|
|
34
41
|
useInteractiveGroups,
|
|
35
42
|
screenReaderContent,
|
|
36
|
-
withScrollbar: withScrollbar,
|
|
37
43
|
firstOptionSticky,
|
|
44
|
+
stickyOptionRef,
|
|
45
|
+
withScrollbar,
|
|
38
46
|
}),
|
|
39
47
|
listBottom ? (React.createElement("li", { role: "option", className: styles['list-bottom'] }, listBottom)) : null));
|
|
40
48
|
};
|