Skip to content

Commit 0c856e8

Browse files
authored
refactor(dropdowns): use transient props where appropriate (#1961)
1 parent d4841cc commit 0c856e8

20 files changed

+153
-150
lines changed

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

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -176,48 +176,34 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
176176
'listboxAriaLabel',
177177
'Options'
178178
);
179-
const triggerProps = {
180-
isAutocomplete,
181-
isBare,
182-
isCompact,
183-
isEditable,
184-
isLabelHovered,
185-
isMultiselectable,
186-
maxHeight,
187-
focusInset,
188-
validation,
189-
...(getTriggerProps({
190-
onFocus: () => {
191-
if (!isDisabled) {
192-
if (isEditable) {
193-
setIsInputHidden(false);
194-
}
179+
const triggerProps = getTriggerProps({
180+
onFocus: () => {
181+
if (!isDisabled) {
182+
if (isEditable) {
183+
setIsInputHidden(false);
184+
}
195185

196-
if (isMultiselectable) {
197-
setIsTagGroupExpanded(true);
198-
}
186+
if (isMultiselectable) {
187+
setIsTagGroupExpanded(true);
188+
}
189+
}
190+
},
191+
onBlur: event => {
192+
if (event.relatedTarget === null || !triggerRef.current?.contains(event.relatedTarget)) {
193+
if (isEditable) {
194+
setIsInputHidden(true);
199195
}
200-
},
201-
onBlur: event => {
202-
if (event.relatedTarget === null || !triggerRef.current?.contains(event.relatedTarget)) {
203-
if (isEditable) {
204-
setIsInputHidden(true);
205-
}
206196

207-
if (isMultiselectable) {
208-
setIsTagGroupExpanded(false);
209-
}
197+
if (isMultiselectable) {
198+
setIsTagGroupExpanded(false);
210199
}
211200
}
212-
}) as HTMLAttributes<HTMLDivElement>)
213-
};
201+
}
202+
}) as HTMLAttributes<HTMLDivElement>;
203+
214204
const inputProps = {
215205
'aria-invalid': validation === 'error' || validation === 'warning',
216206
hidden: isInputHidden,
217-
isBare,
218-
isCompact,
219-
isEditable,
220-
isMultiselectable,
221207
placeholder,
222208
...(getInputProps({
223209
...(_inputProps as IUseComboboxReturnValue['getInputProps'])
@@ -266,12 +252,23 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
266252
return (
267253
<ComboboxContext.Provider value={contextValue}>
268254
<StyledCombobox
269-
isCompact={isCompact}
255+
$isCompact={isCompact}
270256
tabIndex={-1} // HACK: otherwise screenreaders can't read the label
271257
{...props}
272258
ref={ref}
273259
>
274-
<StyledTrigger {...triggerProps}>
260+
<StyledTrigger
261+
$isAutocomplete={isAutocomplete}
262+
$isBare={isBare}
263+
$isCompact={isCompact}
264+
$isEditable={isEditable}
265+
$isLabelHovered={isLabelHovered}
266+
$isMultiselectable={isMultiselectable}
267+
$maxHeight={maxHeight}
268+
$focusInset={focusInset}
269+
$validation={validation}
270+
{...triggerProps}
271+
>
275272
<StyledContainer>
276273
{!!startIcon && (
277274
<StyledInputIcon $isLabelHovered={isLabelHovered} $isCompact={isCompact}>
@@ -291,7 +288,7 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
291288
<StyledTagsButton
292289
disabled={isDisabled}
293290
hidden={isTagGroupExpanded}
294-
isCompact={isCompact}
291+
$isCompact={isCompact}
295292
tabIndex={-1}
296293
type="button"
297294
>
@@ -308,17 +305,23 @@ export const Combobox = forwardRef<HTMLDivElement, IComboboxProps>(
308305
)}
309306
<StyledValue
310307
hidden={!isInputHidden}
311-
isAutocomplete={isAutocomplete}
312-
isBare={isBare}
313-
isCompact={isCompact}
314-
isDisabled={isDisabled}
315-
isEditable={isEditable}
316-
isMultiselectable={isMultiselectable}
317-
isPlaceholder={!(inputValue || renderValue)}
308+
$isAutocomplete={isAutocomplete}
309+
$isBare={isBare}
310+
$isCompact={isCompact}
311+
$isDisabled={isDisabled}
312+
$isEditable={isEditable}
313+
$isMultiselectable={isMultiselectable}
314+
$isPlaceholder={!(inputValue || renderValue)}
318315
>
319316
{renderValue ? renderValue({ selection, inputValue }) : inputValue || placeholder}
320317
</StyledValue>
321-
<StyledInput {...inputProps} />
318+
<StyledInput
319+
$isBare={isBare}
320+
$isCompact={isCompact}
321+
$isEditable={isEditable}
322+
$isMultiselectable={isMultiselectable}
323+
{...inputProps}
324+
/>
322325
</StyledInputGroup>
323326
{!!(hasChevron || endIcon) && (
324327
<StyledInputIcon

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ export const Listbox = forwardRef<HTMLUListElement, IListboxProps>(
123123
const Node = (
124124
<StyledFloatingListbox
125125
data-garden-animate={isVisible ? 'true' : 'false'}
126-
isHidden={!isExpanded}
127-
position={placement === 'bottom-start' ? 'bottom' : 'top'}
126+
$isHidden={!isExpanded}
127+
$position={placement === 'bottom-start' ? 'bottom' : 'top'}
128128
style={{ transform, width }}
129-
zIndex={zIndex}
129+
$zIndex={zIndex}
130130
ref={floatingRef}
131131
>
132132
<StyledListbox
133-
isCompact={isCompact}
134-
maxHeight={maxHeight}
135-
minHeight={minHeight}
133+
$isCompact={isCompact}
134+
$maxHeight={maxHeight}
135+
$minHeight={minHeight}
136136
onMouseDown={composeEventHandlers(onMouseDown, handleMouseDown)}
137137
style={{ height }}
138138
{...props}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const OptGroup = forwardRef<HTMLLIElement, IOptGroupProps>(
4242

4343
return (
4444
<StyledOption
45-
isCompact={isCompact}
45+
$isCompact={isCompact}
4646
$type="group"
4747
onMouseDown={composeEventHandlers(onMouseDown, handleMouseDown)}
4848
role="none"
@@ -51,7 +51,7 @@ export const OptGroup = forwardRef<HTMLLIElement, IOptGroupProps>(
5151
>
5252
<StyledOptionContent>
5353
{!!(content || legend) && (
54-
<StyledOption as="div" isCompact={isCompact} $type="header">
54+
<StyledOption as="div" $isCompact={isCompact} $type="header">
5555
{!!icon && (
5656
<StyledOptionTypeIcon $isCompact={isCompact} $type="header">
5757
{icon}
@@ -60,7 +60,7 @@ export const OptGroup = forwardRef<HTMLLIElement, IOptGroupProps>(
6060
{content || legend}
6161
</StyledOption>
6262
)}
63-
<StyledOptGroup isCompact={isCompact} {...optGroupProps}>
63+
<StyledOptGroup $isCompact={isCompact} {...optGroupProps}>
6464
<StyledListboxSeparator role="none" />
6565
{children}
6666
</StyledOptGroup>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const OptionComponent = forwardRef<HTMLLIElement, IOptionProps>(
6767
return (
6868
<OptionContext.Provider value={contextValue}>
6969
<StyledOption
70-
isActive={isActive}
71-
isCompact={isCompact}
70+
$isActive={isActive}
71+
$isCompact={isCompact}
7272
$type={type}
7373
{...props}
7474
{...optionProps}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const OptionMetaComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivEle
1313
(props, ref) => {
1414
const { isDisabled } = useOptionContext();
1515

16-
return <StyledOptionMeta isDisabled={isDisabled} {...props} ref={ref} />;
16+
return <StyledOptionMeta $isDisabled={isDisabled} {...props} ref={ref} />;
1717
}
1818
);
1919

packages/dropdowns/src/elements/menu/Item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ const ItemComponent = forwardRef<HTMLLIElement, IItemProps>(
8383
<ItemContext.Provider value={contextValue}>
8484
<StyledItem
8585
$type={type}
86-
isCompact={isCompact}
87-
isActive={isActive}
86+
$isCompact={isCompact}
87+
$isActive={isActive}
8888
{...props}
8989
{...itemProps}
9090
ref={mergeRefs([_itemRef, ref])}

packages/dropdowns/src/elements/menu/ItemGroup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export const ItemGroup = forwardRef<HTMLLIElement, IItemGroupProps>(
4444

4545
return (
4646
<ItemGroupContext.Provider value={contextValue}>
47-
<StyledItem isCompact={isCompact} $type="group" {...props} role="none" ref={ref}>
47+
<StyledItem $isCompact={isCompact} $type="group" {...props} role="none" ref={ref}>
4848
<StyledItemContent>
4949
{!!(content || legend) && (
50-
<StyledItem as="div" isCompact={isCompact} $type="header">
50+
<StyledItem as="div" $isCompact={isCompact} $type="header">
5151
{!!icon && (
5252
<StyledItemTypeIcon $isCompact={isCompact} $type="header">
5353
{icon}
@@ -56,7 +56,7 @@ export const ItemGroup = forwardRef<HTMLLIElement, IItemGroupProps>(
5656
{content || legend}
5757
</StyledItem>
5858
)}
59-
<StyledItemGroup isCompact={isCompact} {...groupProps}>
59+
<StyledItemGroup $isCompact={isCompact} {...groupProps}>
6060
<StyledSeparator role="none" />
6161
{children}
6262
</StyledItemGroup>

packages/dropdowns/src/elements/menu/ItemMeta.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ItemMetaComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivEleme
1313
(props, ref) => {
1414
const { isDisabled } = useItemContext();
1515

16-
return <StyledItemMeta isDisabled={isDisabled} {...props} ref={ref} />;
16+
return <StyledItemMeta $isDisabled={isDisabled} {...props} ref={ref} />;
1717
}
1818
);
1919

packages/dropdowns/src/elements/menu/MenuList.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,18 @@ export const MenuList = forwardRef<HTMLUListElement, IMenuListProps>(
144144
const Node = (
145145
<StyledFloatingMenu
146146
data-garden-animate={isVisible}
147-
isHidden={!isExpanded || !isVisible} /* [1] */
148-
position={getMenuPosition(placement)}
149-
zIndex={zIndex}
147+
$isHidden={!isExpanded || !isVisible} /* [1] */
148+
$position={getMenuPosition(placement)}
149+
$zIndex={zIndex}
150150
style={{ transform }}
151151
ref={floatingRef}
152152
>
153153
<StyledMenu
154154
data-garden-animate-arrow={isVisible}
155-
arrowPosition={hasArrow ? getArrowPosition(theme, placement) : undefined}
156-
isCompact={isCompact}
157-
minHeight={minHeight}
158-
maxHeight={maxHeight}
155+
$arrowPosition={hasArrow ? getArrowPosition(theme, placement) : undefined}
156+
$isCompact={isCompact}
157+
$minHeight={minHeight}
158+
$maxHeight={maxHeight}
159159
style={{ height }}
160160
{...props}
161161
ref={ref}

packages/dropdowns/src/views/combobox/StyledCombobox.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { StyledMessage } from './StyledMessage';
1414
const COMPONENT_ID = 'dropdowns.combobox';
1515

1616
interface IStyledComboboxProps extends ThemeProps<DefaultTheme> {
17-
isCompact?: boolean;
17+
$isCompact?: boolean;
1818
}
1919

2020
const sizeStyles = (props: IStyledComboboxProps) => {
21-
const minWidth = `${props.isCompact ? 100 : 144}px`;
22-
const marginTop = `${props.theme.space.base * (props.isCompact ? 1 : 2)}px`;
21+
const minWidth = `${props.$isCompact ? 100 : 144}px`;
22+
const marginTop = `${props.theme.space.base * (props.$isCompact ? 1 : 2)}px`;
2323

2424
return css`
2525
min-width: ${minWidth};

0 commit comments

Comments
 (0)