Skip to content

Commit 7476312

Browse files
dragonlipzSutuSebastiancoderabbitai[bot]
authored
Add an override to useTypeAhead behavior from @floating-ui/react allowing use <input /> in DropDown.Header (#1394)
* add an override to useTypeAhead behavior from @floating-ui/react when using input html types in header of DropDown * fixing up coderabbitai nitpicks since I made additions to this file to help speed future reviews. * Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * format code * Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Sutu Sebastian <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: SutuSebastian <[email protected]>
1 parent 50c860e commit 7476312

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

apps/web/content/docs/components/dropdown.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ title: React Dropdown - Flowbite
33
description: Use the dropdown component to trigger a list of menu items when clicking on an element such as a button or link based on multiple styles, sizes, and placements with React
44
---
55

6-
The dropdown component is a UI component built with React that allows you to show a list of items when clicking on a trigger element (ie. a button) that you can use to build dropdown menus, lists, and more.
6+
The dropdown component is a UI element built with React that displays a list of items when a trigger element (e.g., a button) is clicked. You can use it to build dropdown menus, lists, and more.
77

8-
The default styles are built with the utility classes from Tailwind CSS and you can use the custom props from React to customize the behaviour and positioning of the dropdowns.
8+
The default styles are built using utility classes from Tailwind CSS. You can customize the behavior and positioning of the dropdowns using custom props from React.
99

1010
To start using the component make sure that you have imported it from Flowbite React:
1111

@@ -15,7 +15,7 @@ import { Dropdown } from "flowbite-react";
1515

1616
## Default dropdown
1717

18-
Use this example to create a simple dropdown with a list of menu items by adding child `<Dropdown.Item>` components inside of the main `<Dropdown>` component.
18+
Use this example to create a simple dropdown with a list of menu items by adding child `<Dropdown.Item>` components inside the main `<Dropdown>` component.
1919

2020
<Example name="dropdown.root" />
2121

@@ -29,6 +29,8 @@ Use the `<Dropdown.Divider>` component to add a divider between the dropdown ite
2929

3030
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.
3131

32+
For more complex headers that include an `<input>` or `<TextInput>` control, set `enableTypeAhead` to `false` on the `<Dropdown>` to prevent keystrokes from being interpreted as item searches.
33+
3234
<Example name="dropdown.header" />
3335

3436
## Dropdown items with icon
@@ -63,7 +65,7 @@ Add a custom `onClick` event handler to the `<Dropdown.Item>` component to handl
6365

6466
## Custom trigger
6567

66-
To customize the trigger element you can use `renderTrigger` property.
68+
To customize the trigger element, you can use the `renderTrigger` property.
6769

6870
<Example name="dropdown.customTrigger" />
6971

packages/ui/src/components/Dropdown/Dropdown.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ WithHeader.args = {
6060
),
6161
};
6262

63+
export const WithUsableInputHeader = Template.bind({});
64+
WithUsableInputHeader.storyName = "With usable input header";
65+
WithUsableInputHeader.args = {
66+
enableTypeAhead: false,
67+
children: (
68+
<>
69+
<Dropdown.Header>
70+
<input className="text-black" onChange={action("onChange")} />
71+
</Dropdown.Header>
72+
<Dropdown.Item>Dashboard</Dropdown.Item>
73+
<Dropdown.Item>Settings</Dropdown.Item>
74+
<Dropdown.Item>Earnings</Dropdown.Item>
75+
<Dropdown.Item>Sign out</Dropdown.Item>
76+
</>
77+
),
78+
};
79+
6380
export const Inline = Template.bind({});
6481
Inline.args = {
6582
inline: true,

packages/ui/src/components/Dropdown/Dropdown.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface DropdownProps extends Pick<FloatingProps, "placement" | "trigge
4747
inline?: boolean;
4848
label: ReactNode;
4949
theme?: DeepPartial<FlowbiteDropdownTheme>;
50+
enableTypeAhead?: boolean;
5051
renderTrigger?: (theme: FlowbiteDropdownTheme) => ReactElement;
5152
"data-testid"?: string;
5253
}
@@ -108,6 +109,7 @@ const DropdownComponent: FC<DropdownProps> = ({
108109
className,
109110
dismissOnClick = true,
110111
theme: customTheme = {},
112+
enableTypeAhead = true,
111113
renderTrigger,
112114
...props
113115
}) => {
@@ -164,6 +166,7 @@ const DropdownComponent: FC<DropdownProps> = ({
164166
activeIndex,
165167
selectedIndex,
166168
onMatch: handleTypeaheadMatch,
169+
enabled: enableTypeAhead,
167170
});
168171

169172
const { getReferenceProps, getFloatingProps, getItemProps } = useFloatingInteractions({

0 commit comments

Comments
 (0)