@loadsmart/loadsmart-ui 6.0.8 → 6.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/loadsmart-ui",
3
- "version": "6.0.8",
3
+ "version": "6.0.9",
4
4
  "description": "Miranda UI, a React UI library",
5
5
  "main": "dist",
6
6
  "files": [
@@ -191,6 +191,7 @@ describe('Select', () => {
191
191
 
192
192
  expect(onBlur).toHaveBeenNthCalledWith(1, new MouseEvent('mousedown'))
193
193
  expect(onBlur).toHaveBeenNthCalledWith(2, new KeyboardEvent('keyup'))
194
+ expect(selectEvent.isMenuExpanded(selectInput)).toBe(false)
194
195
  })
195
196
 
196
197
  it('shrinks when an option is selected', async () => {
@@ -314,6 +315,7 @@ describe('Select', () => {
314
315
 
315
316
  expect(await selectEvent.getSelectedOptions(searchInput)).toHaveLength(0)
316
317
  expect(searchInput).toHaveDisplayValue('')
318
+ expect(selectEvent.isMenuExpanded(searchInput)).toBe(false)
317
319
  })
318
320
 
319
321
  it('removes the clear button', async () => {
@@ -30,6 +30,7 @@ import type {
30
30
  SelectDatasourceFunction,
31
31
  SelectProps,
32
32
  SelectStatus,
33
+ SelectValue,
33
34
  useSelectReturn,
34
35
  } from './Select.types'
35
36
 
@@ -223,7 +224,7 @@ function useSelect(props: SelectProps): useSelectReturn {
223
224
  multiple,
224
225
  adapters,
225
226
  onChange: useCallback(
226
- function handleSelectionChange(selected) {
227
+ function handleSelectionChange(selected: SelectValue) {
227
228
  onChange?.({ target: { id, name, value: getValue(selected, multiple) } })
228
229
  },
229
230
  [id, multiple, name, onChange]
@@ -303,13 +304,14 @@ function useSelect(props: SelectProps): useSelectReturn {
303
304
  toggle: dropdown.toggle,
304
305
  expanded: dropdown.expanded,
305
306
  onBlur(event?: MouseEvent | TouchEvent | KeyboardEvent) {
307
+ setQueryTyped(false)
308
+
306
309
  if (!multiple) {
307
310
  setQuery(getDisplayValue(adapters, selectable.selected, multiple))
308
311
  } else {
309
312
  setQuery('')
310
313
  }
311
314
  options.reset()
312
-
313
315
  onBlur?.(event)
314
316
  },
315
317
  expandDisabled,
@@ -338,10 +340,11 @@ function useSelect(props: SelectProps): useSelectReturn {
338
340
  },
339
341
  value: query,
340
342
  onChange(e: ChangeEvent<HTMLInputElement>) {
341
- onQueryChange?.(e)
343
+ const sanitizedValue = e.target.value.replace(/\s+/, '')
342
344
 
345
+ setQueryTyped(sanitizedValue !== '')
346
+ onQueryChange?.(e)
343
347
  setQuery(e.target.value)
344
- setQueryTyped(true)
345
348
  },
346
349
  onFocus: TriggerOnFocusHandler,
347
350
  }
@@ -353,10 +356,10 @@ function useSelect(props: SelectProps): useSelectReturn {
353
356
  function getClearProps() {
354
357
  return {
355
358
  onClick() {
359
+ setQueryTyped(false)
356
360
  setQuery('')
357
361
  selectable.clear()
358
362
  options.reset()
359
-
360
363
  triggerRef.current?.focus()
361
364
  },
362
365
  }