@loadsmart/loadsmart-ui 5.11.1 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Select/Select.types.d.ts +10 -3
- package/dist/components/Select/index.d.ts +1 -1
- package/dist/index.js +65 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Select/Select.test.tsx +19 -0
- package/src/components/Select/Select.tsx +19 -17
- package/src/components/Select/Select.types.ts +13 -3
- package/src/components/Select/index.ts +4 -0
package/package.json
CHANGED
|
@@ -298,6 +298,25 @@ describe('Select', () => {
|
|
|
298
298
|
expect(await selectEvent.getSelectedOptions(searchInput)).toHaveLength(0)
|
|
299
299
|
expect(searchInput).toHaveDisplayValue('')
|
|
300
300
|
})
|
|
301
|
+
|
|
302
|
+
it('removes the clear button', async () => {
|
|
303
|
+
const selectedFruit = generator.pickone([...FRUITS])
|
|
304
|
+
|
|
305
|
+
setup({
|
|
306
|
+
value: selectedFruit as Option,
|
|
307
|
+
hideClear: true,
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
const searchInput = screen.getByLabelText('Select your favorite fruit')
|
|
311
|
+
expect(searchInput).toHaveDisplayValue(selectedFruit.label)
|
|
312
|
+
|
|
313
|
+
const selectedOptions = await selectEvent.getSelectedOptions(searchInput)
|
|
314
|
+
expect(selectedOptions).toHaveLength(1)
|
|
315
|
+
|
|
316
|
+
expect(selectedOptions[0]).toHaveTextContent(selectedFruit.label)
|
|
317
|
+
|
|
318
|
+
expect(screen.queryByTestId('select-trigger-clear')).not.toBeInTheDocument()
|
|
319
|
+
})
|
|
301
320
|
})
|
|
302
321
|
|
|
303
322
|
describe('Multi selection', () => {
|
|
@@ -207,7 +207,7 @@ function renderOptionsMultiple(select: useSelectReturn, components?: Components)
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
function Select(props: SelectProps): JSX.Element {
|
|
210
|
-
const { multiple, placeholder, components, ...others } = props
|
|
210
|
+
const { multiple, placeholder, components, hideClear = false, ...others } = props
|
|
211
211
|
|
|
212
212
|
const select = useSelect(props)
|
|
213
213
|
|
|
@@ -224,24 +224,26 @@ function Select(props: SelectProps): JSX.Element {
|
|
|
224
224
|
return <Loading data-testid="select-trigger-loading">···</Loading>
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
if (select.value) {
|
|
228
|
-
|
|
229
|
-
return <ClearMultiple select={select} />
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!select.disabled) {
|
|
233
|
-
return (
|
|
234
|
-
<CloseButton
|
|
235
|
-
size={12}
|
|
236
|
-
{...getCommonClearButtonProps()}
|
|
237
|
-
{...select.getClearProps()}
|
|
238
|
-
type="button"
|
|
239
|
-
/>
|
|
240
|
-
)
|
|
241
|
-
}
|
|
227
|
+
if (!select.value) {
|
|
228
|
+
return null
|
|
242
229
|
}
|
|
243
230
|
|
|
244
|
-
|
|
231
|
+
if (multiple) {
|
|
232
|
+
return <ClearMultiple select={select} />
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (select.disabled || hideClear) {
|
|
236
|
+
return null
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<CloseButton
|
|
241
|
+
size={12}
|
|
242
|
+
{...getCommonClearButtonProps()}
|
|
243
|
+
{...select.getClearProps()}
|
|
244
|
+
type="button"
|
|
245
|
+
/>
|
|
246
|
+
)
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
return (
|
|
@@ -69,6 +69,12 @@ export type Components = {
|
|
|
69
69
|
|
|
70
70
|
export type CreateOptionPosition = 'first' | 'last'
|
|
71
71
|
|
|
72
|
+
export type OnChange = (event: EventLike<Option | Option[] | null>) => void
|
|
73
|
+
|
|
74
|
+
export type OnCreate = (query: string) => Promise<void | Option> | void | Option
|
|
75
|
+
|
|
76
|
+
export type OnQueryChange = (e: ChangeEvent<HTMLInputElement>) => void
|
|
77
|
+
|
|
72
78
|
export interface SelectProps extends DropdownProps {
|
|
73
79
|
name: string
|
|
74
80
|
placeholder?: string
|
|
@@ -78,11 +84,15 @@ export interface SelectProps extends DropdownProps {
|
|
|
78
84
|
datasources?: SelectDatasourceFunction<any>[]
|
|
79
85
|
options?: GenericOption[]
|
|
80
86
|
components?: Components
|
|
81
|
-
onChange?:
|
|
82
|
-
onCreate?:
|
|
83
|
-
onQueryChange?:
|
|
87
|
+
onChange?: OnChange
|
|
88
|
+
onCreate?: OnCreate
|
|
89
|
+
onQueryChange?: OnQueryChange
|
|
84
90
|
isValidNewOption?: ((query: string) => boolean) | boolean
|
|
85
91
|
createOptionPosition?: CreateOptionPosition
|
|
92
|
+
/**
|
|
93
|
+
* Hide the clear button on the Single Select.
|
|
94
|
+
*/
|
|
95
|
+
hideClear?: boolean
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
export type SelectOptionProps = {
|
|
@@ -4,5 +4,9 @@ export type {
|
|
|
4
4
|
useSelectExternalReturn as useSelectReturn,
|
|
5
5
|
SelectComponentsOptionProps as SelectOptionProps,
|
|
6
6
|
SelectComponentsEmptyProps as SelectEmptyProps,
|
|
7
|
+
Option as SelectOption,
|
|
8
|
+
OnChange as SelectOnChange,
|
|
9
|
+
OnCreate as SelectOnCreate,
|
|
10
|
+
OnQueryChange as SelectOnQueryChange,
|
|
7
11
|
} from './Select.types'
|
|
8
12
|
export { useSelectExternal as useSelect } from './useSelectExternal'
|