|
1 | 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | import React, { ReactNode, useEffect, useRef, useState } from 'react'; |
| 4 | +import clsx from 'clsx'; |
4 | 5 |
|
5 | 6 | import { useMergeRefs } from '@cloudscape-design/component-toolkit/internal'; |
6 | 7 |
|
7 | 8 | import { getBaseProps } from '../../internal/base-component'; |
8 | 9 | import CheckboxIcon from '../../internal/components/checkbox-icon'; |
9 | 10 | import Option from '../../internal/components/option'; |
10 | 11 | import { OptionDefinition } from '../../internal/components/option/interfaces'; |
| 12 | +import { getTestOptionIndexes } from '../../internal/components/options-list/utils/test-indexes'; |
11 | 13 | import SelectableItem from '../../internal/components/selectable-item'; |
12 | 14 | import Tooltip from '../../internal/components/tooltip'; |
13 | 15 | import useHiddenDescription from '../../internal/hooks/use-hidden-description'; |
14 | 16 | import { MultiselectProps } from '../../multiselect/interfaces'; |
15 | 17 | import { ItemProps } from './item'; |
16 | 18 |
|
| 19 | +import optionStyles from '../../internal/components/option/styles.css.js'; |
17 | 20 | import styles from './styles.css.js'; |
18 | 21 | interface MultiselectItemProps extends ItemProps { |
19 | 22 | indeterminate?: boolean; |
@@ -62,8 +65,13 @@ const MultiSelectItem = ( |
62 | 65 |
|
63 | 66 | const [canShowTooltip, setCanShowTooltip] = useState(true); |
64 | 67 | useEffect(() => setCanShowTooltip(true), [highlighted]); |
| 68 | + const { throughIndex, inGroupIndex, groupIndex } = getTestOptionIndexes(option) || {}; |
| 69 | + |
65 | 70 | return ( |
66 | 71 | <SelectableItem |
| 72 | + data-test-index={throughIndex} |
| 73 | + data-in-group-index={inGroupIndex} |
| 74 | + data-group-index={groupIndex} |
67 | 75 | disableContentStyling={!!renderOption} |
68 | 76 | ariaChecked={isParent && indeterminate ? 'mixed' : Boolean(selected)} |
69 | 77 | selected={selected} |
@@ -100,13 +108,22 @@ const MultiSelectItem = ( |
100 | 108 | </div> |
101 | 109 | )} |
102 | 110 | {renderOption ? ( |
103 | | - renderOption({ |
104 | | - option: option.option, |
105 | | - selected: !!selected, |
106 | | - highlighted: !!highlighted, |
107 | | - disabled: !!disabled, |
108 | | - type: option.type !== 'use-entered' ? (option.type ?? 'child') : 'child', |
109 | | - }) |
| 111 | + <div |
| 112 | + data-value={wrappedOption.value} |
| 113 | + className={clsx(optionStyles.option, { |
| 114 | + disabled: !!disabled, |
| 115 | + selected: !!selected, |
| 116 | + highlighted: !!highlighted, |
| 117 | + })} |
| 118 | + > |
| 119 | + {renderOption({ |
| 120 | + option: option.option, |
| 121 | + selected: !!selected, |
| 122 | + highlighted: !!highlighted, |
| 123 | + disabled: !!disabled, |
| 124 | + type: option.type !== 'use-entered' ? (option.type ?? 'child') : 'child', |
| 125 | + })} |
| 126 | + </div> |
110 | 127 | ) : ( |
111 | 128 | <Option |
112 | 129 | option={{ ...wrappedOption, disabled }} |
|
0 commit comments