+ );
+}`;
+
+const react = {
+ "/App.jsx": App,
+ "/data.js": data,
+ "/PetBoldIcon.jsx": PetBoldIcon,
+};
+
+export default {
+ ...react,
+};
diff --git a/apps/docs/content/docs/components/select.mdx b/apps/docs/content/docs/components/select.mdx
index 0469b09cab..eee9c15922 100644
--- a/apps/docs/content/docs/components/select.mdx
+++ b/apps/docs/content/docs/components/select.mdx
@@ -148,6 +148,12 @@ You can combine the `isInvalid` and `errorMessage` properties to show an invalid
+### Clear Button
+
+If you pass the `isClearable` property to the select, it will have a clear button which will be visible only when a value is selected.
+
+
+
### Controlled
You can use the `selectedKeys` and `onSelectionChange` / `onChange` properties to control the select value.
@@ -383,6 +389,7 @@ the popover and listbox components.
| isDisabled | `boolean` | Whether the select is disabled. | `false` |
| isMultiline | `boolean` | Whether the select should allow multiple lines of text. | `false` |
| isInvalid | `boolean` | Whether the select is invalid. | `false` |
+| isClearable | `boolean` | Whether the select should have a clear button. | `false` |
| validationState | `valid` \| `invalid` | Whether the select should display its "valid" or "invalid" visual styling. (**Deprecated**) use **isInvalid** instead. | - |
| showScrollIndicators | `boolean` | Whether the select should show scroll indicators when the listbox is scrollable. | `true` |
| autoFocus | `boolean` | Whether the select should be focused on the first mount. | `false` |
@@ -403,7 +410,7 @@ the popover and listbox components.
| onSelectionChange | `(keys: "all" \| Set & {anchorKey?: string; currentKey?: string}) => void` | Callback fired when the selected keys change. |
| onChange | `React.ChangeEvent` | Native select change event, fired when the selected value changes. |
| renderValue | [RenderValueFunction](#render-value-function) | Function to render the value of the select. It renders the selected item by default. |
-
+| onClear | `() => void` | Handler that is called when the clear button is clicked.
---
### SelectItem Props
diff --git a/packages/components/select/package.json b/packages/components/select/package.json
index fe40e2aa98..6520671444 100644
--- a/packages/components/select/package.json
+++ b/packages/components/select/package.json
@@ -35,7 +35,7 @@
},
"peerDependencies": {
"@nextui-org/system": ">=2.0.0",
- "@nextui-org/theme": ">=2.1.0",
+ "@nextui-org/theme": ">=2.3.0",
"framer-motion": ">=11.5.6",
"react": ">=18",
"react-dom": ">=18"
diff --git a/packages/components/select/src/select.tsx b/packages/components/select/src/select.tsx
index 87ee33d17a..65a615a687 100644
--- a/packages/components/select/src/select.tsx
+++ b/packages/components/select/src/select.tsx
@@ -1,6 +1,6 @@
import {Listbox} from "@nextui-org/listbox";
import {FreeSoloPopover} from "@nextui-org/popover";
-import {ChevronDownIcon} from "@nextui-org/shared-icons";
+import {ChevronDownIcon, CloseFilledIcon} from "@nextui-org/shared-icons";
import {Spinner} from "@nextui-org/spinner";
import {forwardRef} from "@nextui-org/system";
import {ScrollShadow} from "@nextui-org/scroll-shadow";
@@ -29,8 +29,10 @@ function Select(props: Props, ref: ForwardedRef(props: Props, ref: ForwardedRef {
+ if (isClearable && state.selectedItems?.length) {
+ return ;
+ }
+
+ return null;
+ }, [isClearable, getClearButtonProps, state.selectedItems?.length]);
+
+ const end = useMemo(() => {
+ if (clearButton) {
+ return (
+