Skip to content

Commit 32c6d11

Browse files
authored
feat(combobox): add isHidden prop to Option component (#1678)
1 parent d912116 commit 32c6d11

File tree

8 files changed

+147
-20
lines changed

8 files changed

+147
-20
lines changed

package-lock.json

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

packages/dropdowns.next/demo/stories/data.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export const OPTIONS: Options = [
104104
meta: 'Poison',
105105
icon: true,
106106
tagProps: {
107-
'aria-label': 'Press delete or backspace to remove',
108107
isPill: true,
109108
removeLabel: 'Remove'
110109
},
@@ -120,6 +119,18 @@ export const OPTIONS: Options = [
120119
isPill: true,
121120
removeLabel: 'Remove'
122121
}
122+
},
123+
{
124+
value: 'flower-05',
125+
label: 'Lily-Rose',
126+
meta: 'Depp',
127+
icon: true,
128+
tagProps: {
129+
'aria-label': 'Press delete or backspace to remove',
130+
isPill: true,
131+
removeLabel: 'Remove'
132+
},
133+
isHidden: true
123134
}
124135
]
125136
},

packages/dropdowns.next/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.0.11",
25+
"@zendeskgarden/container-combobox": "^1.1.0",
2626
"@zendeskgarden/container-menu": "^0.3.0",
2727
"@zendeskgarden/container-utilities": "^1.0.0",
2828
"@zendeskgarden/react-buttons": "^8.73.4",

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ interface ITestOptionProps extends Partial<IOptionProps> {
1919
}
2020

2121
const TestOption = forwardRef<HTMLLIElement, ITestOptionProps>(
22-
({ optionTestId = 'option', value = 'test', children, ...props }, ref) => (
22+
({ optionTestId = 'option', value = 'test', tagProps, children, ...props }, ref) => (
2323
<Field>
2424
<Combobox defaultExpanded isMultiselectable>
2525
<Option
2626
data-test-id={optionTestId}
27-
tagProps={{ 'data-test-id': 'tag' } as HTMLAttributes<HTMLDivElement>}
27+
tagProps={{ 'data-test-id': 'tag', ...tagProps } as HTMLAttributes<HTMLDivElement>}
2828
value={value}
2929
{...props}
3030
ref={ref}
@@ -90,6 +90,16 @@ describe('Option', () => {
9090
expect(tag).not.toHaveAttribute('tabindex');
9191
});
9292

93+
it('renders hidden as expected', () => {
94+
const { getByTestId } = render(<TestOption isHidden isSelected tagProps={{ isPill: true }} />);
95+
const option = getByTestId('option');
96+
const tag = getByTestId('tag');
97+
98+
expect(option).toHaveAttribute('aria-hidden', 'true');
99+
expect(option).toHaveStyleRule('clip', 'rect(0 0 0 0)', { modifier: '[aria-hidden="true"]' });
100+
expect(tag).toHaveStyleRule('border-radius', '100px');
101+
});
102+
93103
it('renders value text as expected', () => {
94104
const { getByTestId } = render(<TestOption />);
95105
const option = getByTestId('option');

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { OptionMeta } from './OptionMeta';
2525
import { toOption, toString } from './utils';
2626

2727
const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
28-
({ children, icon, isDisabled, isSelected, label, type, value, ...props }, ref) => {
28+
({ children, icon, isDisabled, isHidden, isSelected, label, type, value, ...props }, ref) => {
2929
const contextValue = useMemo(() => ({ isDisabled }), [isDisabled]);
3030
const { activeValue, getOptionProps, isCompact } = useComboboxContext();
3131
const isActive = value === activeValue;
@@ -58,7 +58,7 @@ const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
5858
return <SelectedIcon />;
5959
}
6060
};
61-
const option = toOption({ value, label, isDisabled, isSelected });
61+
const option = toOption({ value, label, isDisabled, isHidden, isSelected });
6262
const optionProps = getOptionProps({
6363
option,
6464
ref: mergeRefs([optionRef, ref])
@@ -90,6 +90,7 @@ OptionComponent.propTypes = {
9090
icon: PropTypes.any,
9191
isDisabled: PropTypes.bool,
9292
isSelected: PropTypes.bool,
93+
isHidden: PropTypes.bool,
9394
label: PropTypes.string,
9495
tagProps: PropTypes.object,
9596
type: PropTypes.oneOf(OPTION_TYPE),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const toOption = (props: IOptionProps): IOption => {
3030
return {
3131
value: props.value,
3232
label: props.label,
33+
hidden: props.isHidden,
3334
disabled: props.isDisabled,
3435
selected: props.isSelected
3536
};

packages/dropdowns.next/src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ export interface IOptionProps extends Omit<LiHTMLAttributes<HTMLLIElement>, 'val
182182
icon?: ReactElement;
183183
/** Indicates that the option is not interactive */
184184
isDisabled?: boolean;
185+
/** Hides the option while retaining props (i.e. selected `tagProps`) */
186+
isHidden?: boolean;
185187
/** Determines the initial selection state for the option */
186188
isSelected?: boolean;
187189
/** Sets the text label of the option (defaults to `value`) */

packages/dropdowns.next/src/views/combobox/StyledOption.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import styled, { ThemeProps, DefaultTheme, css } from 'styled-components';
9-
import { math } from 'polished';
9+
import { hideVisually, math } from 'polished';
1010
import { retrieveComponentStyles, DEFAULT_THEME, getColor } from '@zendeskgarden/react-theming';
1111
import { OptionType } from '../../types';
1212

@@ -99,6 +99,10 @@ export const StyledOption = styled.li.attrs({
9999
cursor: default;
100100
}
101101
102+
&[aria-hidden='true'] {
103+
${hideVisually()};
104+
}
105+
102106
${props => retrieveComponentStyles(COMPONENT_ID, props)};
103107
`;
104108

0 commit comments

Comments
 (0)