File tree 3 files changed +30
-1
lines changed
packages/bento-design-system
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export function BaseSelect<A>(props: Props<A>) {
55
55
autoFocus,
56
56
menuSize = dropdownConfig . defaultMenuSize ,
57
57
searchable,
58
+ clearable = true ,
58
59
} = props ;
59
60
60
61
return (
@@ -79,7 +80,11 @@ export function BaseSelect<A>(props: Props<A>) {
79
80
onChange ( multiValue . map ( ( a ) => a . value ) ) ;
80
81
} else {
81
82
const singleValue = o as SingleValueT < SelectOption < A > > ;
82
- onChange ( singleValue == null ? undefined : singleValue . value ) ;
83
+ if ( clearable ) {
84
+ onChange ( singleValue == null ? undefined : singleValue . value ) ;
85
+ } else {
86
+ singleValue != null && onChange ( singleValue . value ) ;
87
+ }
83
88
}
84
89
} }
85
90
onBlur = { onBlur }
Original file line number Diff line number Diff line change @@ -11,13 +11,15 @@ export type SelectOption<A> = Omit<
11
11
12
12
export type BaseSingleProps = {
13
13
isMulti ?: false ;
14
+ clearable ?: boolean ;
14
15
} ;
15
16
16
17
export type BaseMultiProps = {
17
18
isMulti : true ;
18
19
showMultiSelectBulkActions ?: boolean ;
19
20
selectAllButtonLabel ?: LocalizedString ;
20
21
clearAllButtonLabel ?: LocalizedString ;
22
+ clearable ?: never ;
21
23
} & (
22
24
| {
23
25
multiSelectMode ?: "summary" ;
Original file line number Diff line number Diff line change 7
7
SelectField ,
8
8
BentoConfigProvider ,
9
9
SelectFieldProps ,
10
+ SelectOption ,
10
11
} from ".." ;
12
+ import { useState } from "react" ;
11
13
12
14
const meta = {
13
15
component : SelectField ,
@@ -191,3 +193,23 @@ export const CustomListConfig = {
191
193
) ,
192
194
] ,
193
195
} satisfies Story ;
196
+
197
+ // NOTE(gabro): using a render function instead of just args, because the `value/onChange` trick we
198
+ // use to make the story controlled doesn't play well with the implementation of `clearable`
199
+ export const NotClearable = {
200
+ args : {
201
+ clearable : false ,
202
+ } ,
203
+ render : ( args ) => {
204
+ const [ value , onChange ] = useState < number | undefined > ( undefined ) ;
205
+ return (
206
+ < SelectField
207
+ label = { args . label }
208
+ clearable = { args . clearable }
209
+ options = { args . options as SelectOption < number > [ ] }
210
+ value = { value }
211
+ onChange = { onChange }
212
+ />
213
+ ) ;
214
+ } ,
215
+ } satisfies Story ;
You can’t perform that action at this time.
0 commit comments