Skip to content

Commit e35cf62

Browse files
committed
Add format value option
1 parent c187e4e commit e35cf62

File tree

7 files changed

+4350
-453
lines changed

7 files changed

+4350
-453
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ This table shows all the options available in react-tailwindcss-select.
234234
| `isSearchable` | `Boolean` | `false` | Indicates if you can search the elements of the select field. |
235235
| [`formatGroupLabel`](#formatGroupLabel) | `Function` | `null` | Allows you to use a custom rendering template for each subgroup title |
236236
| [`formatOptionLabel`](#formatOptionLabel) | `Function` | `null` | Allows you to use a custom rendering template for each option in the list |
237+
| `formatValue` | `Function` | `null` | Allows your to format the resulted value |
237238
| `loading` | `Boolean` | `false` | Indicates if you want a loader to appear in the field. |
238239
| `menuIsOpen` | `Boolean` | `false` | Indicates if you want the options menu to be displayed by default. |
239240
| `noOptionsMessage` | `String` | `No results found` | Default message when there is no option in the select field. |

package-lock.json

Lines changed: 3951 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "react-tailwindcss-select",
3-
"version": "1.8.5",
2+
"name": "react-tailwindcss-select-plus",
3+
"version": "1.8.9",
44
"description": "A select input made with React js and Tailwind CSS",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",
77
"types": "dist/index.d.ts",
8-
"author": "onesine",
8+
"author": "mennovanhout",
99
"license": "MIT",
1010
"scripts": {
1111
"watch": "rollup -c -w",
@@ -21,7 +21,7 @@
2121
},
2222
"repository": {
2323
"type": "git",
24-
"url": "https://github.com/onesine/react-tailwindcss-select"
24+
"url": "https://github.com/mennovanhout/react-tailwindcss-select"
2525
},
2626
"keywords": [
2727
"combobox",

src/components/Item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ const Item: React.FC<ItemProps> = ({ item, primaryColor }) => {
6565
<li
6666
tabIndex={0}
6767
onKeyDown={(e: React.KeyboardEvent<HTMLLIElement>) => {
68-
if (e.key === ' ' || e.key === 'Enter') {
69-
handleValueChange(item)
68+
if (e.key === " " || e.key === "Enter") {
69+
handleValueChange(item);
7070
}
7171
}}
7272
aria-selected={isSelected}

src/components/Select.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Select: React.FC<SelectProps> = ({
2727
primaryColor = DEFAULT_THEME,
2828
formatGroupLabel = null,
2929
formatOptionLabel = null,
30+
formatValue = null,
3031
classNames
3132
}) => {
3233
const [open, setOpen] = useState<boolean>(menuIsOpen);
@@ -185,9 +186,15 @@ const Select: React.FC<SelectProps> = ({
185186
>
186187
<div className="grow pl-2.5 py-2 pr-2 flex flex-wrap gap-1">
187188
{!isMultiple ? (
188-
<p className="truncate cursor-default select-none">
189-
{value && !Array.isArray(value) ? value.label : placeholder}
190-
</p>
189+
formatValue && typeof formatValue === "function" ? (
190+
formatValue(
191+
value && !Array.isArray(value) ? value!.label : placeholder
192+
)
193+
) : (
194+
<p className="truncate cursor-default select-none">
195+
{value && !Array.isArray(value) ? value.label : placeholder}
196+
</p>
197+
)
191198
) : (
192199
<>
193200
{value === null && placeholder}

src/components/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ export interface SelectProps {
5151
primaryColor: string;
5252
formatGroupLabel?: ((data: GroupOption) => JSX.Element) | null;
5353
formatOptionLabel?: ((data: Option) => JSX.Element) | null;
54+
formatValue?: ((label: string) => JSX.Element) | null;
5455
classNames?: ClassNames;
5556
}

0 commit comments

Comments
 (0)