Skip to content

Commit

Permalink
feat: remove trigger component
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron committed Apr 30, 2024
1 parent fcac965 commit 9181cfb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
1 change: 0 additions & 1 deletion packages/ui/src/components/ComboBox/ComboBox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function ComboBoxStory(args: Pick<ComboBoxProps, 'debounce'>) {
<ComboBox.Input>
<ComboBox.InputField ref={inputRef} placeholder="Type a fruit name" />
</ComboBox.Input>
<ComboBox.Trigger />
<ComboBox.Content />
</ComboBox>
);
Expand Down
59 changes: 26 additions & 33 deletions packages/ui/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,6 @@ export const ComboBoxInput = createComponent<ComboBoxInputProps, typeof Input>({
baseElement: Input,
});

export const ComboBoxTrigger = createComponent<{}, typeof Popover.Trigger>({
id: 'ComboBoxTrigger',
baseElement: Popover.Trigger,
render: (Root, { ...props }) => {
return (
<Root {...props}>
<div />
</Root>
);
},
});

export const ComboBoxInputField = createComponent<
ComboBoxInputFieldProps,
typeof Input.Field
Expand Down Expand Up @@ -268,27 +256,33 @@ export const ComboBoxContent = createComponent<
useComboBoxContext();

return (
<Popover.Content
// Goes against accessibility rules but otherwise we'd be constantly losing focus on the input
onOpenAutoFocus={(e) => e.preventDefault()}
>
<Flex
className={className}
direction="column"
gap="2"
style={style}
{...props}
<>
{/* Popover uses the trigger's position and container to determine the position and size of the content window. */}
<Popover.Trigger>
<div />
</Popover.Trigger>
<Popover.Content
// Goes against accessibility rules but otherwise we'd be constantly losing focus on the input
onOpenAutoFocus={(e) => e.preventDefault()}
>
{filteredSuggestions.map((suggestion: string) => (
<ComboBoxItem
key={itemNameSelector?.(suggestion) ?? (suggestion as string)}
suggestion={suggestion}
itemNameSelector={itemNameSelector}
onItemSelected={handleSuggestionClick}
/>
))}
</Flex>
</Popover.Content>
<Flex
className={className}
direction="column"
gap="2"
style={style}
{...props}
>
{filteredSuggestions.map((suggestion: string) => (
<ComboBoxItem
key={itemNameSelector?.(suggestion) ?? (suggestion as string)}
suggestion={suggestion}
itemNameSelector={itemNameSelector}
onItemSelected={handleSuggestionClick}
/>
))}
</Flex>
</Popover.Content>
</>
);
},
});
Expand All @@ -300,6 +294,5 @@ export const ComboBox = withNamespace(
Content: ComboBoxContent,
Input: ComboBoxInput,
InputField: ComboBoxInputField,
Trigger: ComboBoxTrigger,
},
);

0 comments on commit 9181cfb

Please sign in to comment.