Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an override to useTypeAhead behavior from @floating-ui/react allowing use <input /> in DropDown.Header #1394

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

SutuSebastian marked this conversation as resolved.
Show resolved Hide resolved
<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
Loading