Skip to content

Commit

Permalink
add an override to useTypeAhead behavior from @floating-ui/react when…
Browse files Browse the repository at this point in the history
… using input html types in header of DropDown
  • Loading branch information
dragonlipz committed May 13, 2024
1 parent 2afa3c8 commit 9ade36f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/web/content/docs/components/dropdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Use the `<Dropdown.Divider>` component to add a divider between the dropdown ite

Use the `<Dropdown.Header>` component to add a header to the dropdown. You can use this to add a user profile image and name, for example.

For more complex headers that include an `<input>` or `<TextInput>` control, it's necessary to set `enableTypeAhead` to false on the `<Dropdown>` to prevent item search interpretation of keystrokes.

<Example name="dropdown.header" />

## Dropdown items with icon
Expand Down
17 changes: 17 additions & 0 deletions packages/ui/src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ WithHeader.args = {
),
};

export const WithUsableInputHeader = Template.bind({});
WithUsableInputHeader.storyName = "With usable input header";
WithUsableInputHeader.args = {
enableTypeAhead: false,
children: (
<>
<Dropdown.Header>
<input className="text-black" onChange={action("onChange")} />
</Dropdown.Header>
<Dropdown.Item>Dashboard</Dropdown.Item>
<Dropdown.Item>Settings</Dropdown.Item>
<Dropdown.Item>Earnings</Dropdown.Item>
<Dropdown.Item>Sign out</Dropdown.Item>
</>
),
};

export const Inline = Template.bind({});
Inline.args = {
inline: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface DropdownProps extends Pick<FloatingProps, "placement" | "trigge
inline?: boolean;
label: ReactNode;
theme?: DeepPartial<FlowbiteDropdownTheme>;
enableTypeAhead?: boolean;
renderTrigger?: (theme: FlowbiteDropdownTheme) => ReactElement;
"data-testid"?: string;
}
Expand Down Expand Up @@ -108,6 +109,7 @@ const DropdownComponent: FC<DropdownProps> = ({
className,
dismissOnClick = true,
theme: customTheme = {},
enableTypeAhead = true,
renderTrigger,
...props
}) => {
Expand Down Expand Up @@ -164,6 +166,7 @@ const DropdownComponent: FC<DropdownProps> = ({
activeIndex,
selectedIndex,
onMatch: handleTypeaheadMatch,
enabled: enableTypeAhead,
});

const { getReferenceProps, getFloatingProps, getItemProps } = useFloatingInteractions({
Expand Down

0 comments on commit 9ade36f

Please sign in to comment.