Skip to content

Commit c26a7bf

Browse files
authored
feat(dropdowns)!: removes object type from Option value prop (#1773)
1 parent c578897 commit c26a7bf

File tree

8 files changed

+538
-553
lines changed

8 files changed

+538
-553
lines changed

package-lock.json

Lines changed: 526 additions & 527 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dropdowns/demo/stories/ComboboxStory.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import {
2222
Tag
2323
} from '@zendeskgarden/react-dropdowns';
2424
import { IOption, Options } from './types';
25-
import { toString } from '../../src/elements/combobox/utils';
2625

27-
const toLabel = (option: IOption) => option.label || toString(option);
26+
const toLabel = (option: IOption) => option.label || option.value;
2827

2928
const ComboboxOption = ({ icon, meta, ...props }: IOption) => {
3029
const Svg = props.tagProps?.isPill ? Avatar : Icon;
@@ -157,7 +156,7 @@ export const ComboboxStory: Story<IArgs> = ({
157156
<OptGroup key={index} icon={icon ? <Icon /> : undefined} {...option}>
158157
{option.options.map(({ icon: groupIcon, ...groupOption }) => (
159158
<ComboboxOption
160-
key={toString(groupOption)}
159+
key={groupOption.value}
161160
icon={groupIcon}
162161
{...groupOption}
163162
tagProps={getTagProps({ icon: groupIcon, ...groupOption })}
@@ -166,7 +165,7 @@ export const ComboboxStory: Story<IArgs> = ({
166165
</OptGroup>
167166
) : (
168167
<ComboboxOption
169-
key={toString(option)}
168+
key={option.value}
170169
icon={icon}
171170
{...option}
172171
tagProps={getTagProps({ icon, ...option })}

packages/dropdowns/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"types": "dist/typings/index.d.ts",
2323
"dependencies": {
2424
"@floating-ui/react-dom": "^2.0.0",
25-
"@zendeskgarden/container-combobox": "^1.1.4",
25+
"@zendeskgarden/container-combobox": "^2.0.0",
2626
"@zendeskgarden/container-menu": "^0.3.0",
2727
"@zendeskgarden/container-utilities": "^2.0.0",
2828
"@zendeskgarden/react-buttons": "^9.0.0-next.6",

packages/dropdowns/src/elements/combobox/Option.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
StyledOptionTypeIcon
2323
} from '../../views';
2424
import { OptionMeta } from './OptionMeta';
25-
import { toOption, toString } from './utils';
25+
import { toOption } from './utils';
2626

2727
const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
2828
({ children, icon, isDisabled, isHidden, isSelected, label, type, value, ...props }, ref) => {
@@ -77,7 +77,7 @@ const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
7777
{renderActionIcon(type)}
7878
</StyledOptionTypeIcon>
7979
{icon && <StyledOptionIcon>{icon}</StyledOptionIcon>}
80-
<StyledOptionContent>{children || label || toString({ value })}</StyledOptionContent>
80+
<StyledOptionContent>{children || label || value}</StyledOptionContent>
8181
</StyledOption>
8282
</OptionContext.Provider>
8383
);
@@ -94,7 +94,7 @@ OptionComponent.propTypes = {
9494
label: PropTypes.string,
9595
tagProps: PropTypes.object,
9696
type: PropTypes.oneOf(OPTION_TYPE),
97-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
97+
value: PropTypes.string.isRequired
9898
};
9999

100100
/**

packages/dropdowns/src/elements/combobox/Tag.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import { Tooltip } from '@zendeskgarden/react-tooltips';
1313
import { ITagProps } from '../../types';
1414
import useComboboxContext from '../../context/useComboboxContext';
1515
import { StyledTag } from '../../views';
16-
import { toString } from './utils';
1716
import { TagAvatar } from './TagAvatar';
1817

1918
const TagComponent = forwardRef<HTMLDivElement, ITagProps>(
2019
({ children, option, removeLabel, tooltipZIndex, ...props }, ref) => {
2120
const { getTagProps, isCompact, removeSelection } = useComboboxContext();
22-
const text = option.label || toString(option);
21+
const text = option.label || option.value;
2322
const ariaLabel = useText(
2423
/* eslint-disable-next-line @typescript-eslint/no-use-before-define */
2524
Tag,

packages/dropdowns/src/elements/combobox/TagGroup.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import React, { PropsWithChildren } from 'react';
9-
import { toString } from './utils';
109
import { Tag } from './Tag';
1110
import { ITagGroupProps } from '../../types';
1211

@@ -21,16 +20,15 @@ export const TagGroup = ({
2120
}: PropsWithChildren<ITagGroupProps>) => (
2221
<>
2322
{selection.map((option, index) => {
24-
const key = toString(option);
2523
const disabled = isDisabled || option.disabled;
2624

2725
return (
2826
<Tag
29-
key={key}
27+
key={option.value}
3028
hidden={!isExpanded && index >= maxTags}
3129
option={{ ...option, disabled }}
3230
tooltipZIndex={listboxZIndex ? listboxZIndex + 1 : undefined}
33-
{...optionTagProps[key]}
31+
{...optionTagProps[option.value]}
3432
/>
3533
);
3634
})}

packages/dropdowns/src/elements/combobox/utils.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ import { Children, ReactNode, isValidElement } from 'react';
99
import { IOption, IUseComboboxProps } from '@zendeskgarden/container-combobox';
1010
import { IOptGroupProps, IOptionProps } from '../../types';
1111

12-
/**
13-
* Convert an option object to a string.
14-
*
15-
* @param option An option of type `IOption`.
16-
*
17-
* @returns A string based on `option.value`.
18-
*/
19-
export const toString = (option: IOption) =>
20-
typeof option.value === 'string' ? option.value : JSON.stringify(option.value);
21-
2212
/**
2313
* Convert `Option` props to a valid object for `useCombobox`.
2414
*
@@ -55,7 +45,7 @@ export const toOptions = (
5545
if (isValidElement(option)) {
5646
if ('value' in option.props) {
5747
retVal.push(toOption(option.props));
58-
optionTagProps[toString(option.props)] = option.props.tagProps;
48+
optionTagProps[option.props.value] = option.props.tagProps;
5949
} else {
6050
const props: IOptGroupProps = option.props;
6151
const groupOptions = toOptions(props.children, optionTagProps) as IOption[];

packages/dropdowns/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export interface IOptionProps extends Omit<LiHTMLAttributes<HTMLLIElement>, 'val
176176
/** Determines the option type */
177177
type?: OptionType;
178178
/** Sets the unique value that is returned upon selection */
179-
value: string | object;
179+
value: string;
180180
}
181181

182182
export interface IOptGroupProps extends Omit<LiHTMLAttributes<HTMLLIElement>, 'content'> {

0 commit comments

Comments
 (0)