@butternutbox/pawprint-native 1.3.0 → 1.3.1

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": "@butternutbox/pawprint-native",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "description": "ButternutBox Pawprint Design System - React Native Components",
6
6
  "main": "./dist/index.cjs",
@@ -128,6 +128,7 @@ export const TextInput = React.forwardRef<HTMLInputElement, any>(
128
128
  placeholderTextColor: _placeholderTextColor,
129
129
  onChangeText,
130
130
  onChange,
131
+ onBlur,
131
132
  value,
132
133
  defaultValue,
133
134
  placeholder,
@@ -147,6 +148,7 @@ export const TextInput = React.forwardRef<HTMLInputElement, any>(
147
148
  placeholder={placeholder}
148
149
  disabled={editable === false}
149
150
  aria-disabled={accessibilityState?.disabled}
151
+ onBlur={onBlur}
150
152
  onChange={(e) => {
151
153
  onChangeText?.(e.target.value)
152
154
  onChange?.(e)
@@ -375,6 +375,24 @@ describe("SelectField", () => {
375
375
  fireEvent.click(screen.getByTestId("select-overlay"))
376
376
  expect(screen.queryByPlaceholderText("Search...")).not.toBeInTheDocument()
377
377
  })
378
+
379
+ it("re-focuses the search input when it blurs while the dropdown is open", () => {
380
+ renderWithTheme(
381
+ <SelectField label="Country" placeholder="Select a country" searchable>
382
+ <SelectField.Item value="uk">United Kingdom</SelectField.Item>
383
+ </SelectField>
384
+ )
385
+
386
+ openDropdownWithContent()
387
+ const input = screen.getByPlaceholderText("Search...")
388
+ vi.useFakeTimers()
389
+ input.blur()
390
+ expect(input).not.toHaveFocus()
391
+
392
+ act(() => vi.advanceTimersByTime(50))
393
+ vi.useRealTimers()
394
+ expect(input).toHaveFocus()
395
+ })
378
396
  })
379
397
 
380
398
  describe("when searchable with an async query", () => {
@@ -315,6 +315,17 @@ const SelectFieldRoot = React.forwardRef<View, SelectFieldProps>(
315
315
  // Re-running here re-focuses the input so typing is not interrupted.
316
316
  }, [isOpen, searchable, isSearching, searchQuery])
317
317
 
318
+ const isOpenRef = React.useRef(isOpen)
319
+ React.useEffect(() => {
320
+ isOpenRef.current = isOpen
321
+ })
322
+
323
+ const handleSearchBlur = () => {
324
+ setTimeout(() => {
325
+ if (isOpenRef.current) searchInputRef.current?.focus()
326
+ }, 50)
327
+ }
328
+
318
329
  const isCompound = React.Children.toArray(children).some(
319
330
  (child) =>
320
331
  React.isValidElement(child) && child.type === SelectFieldContent
@@ -447,6 +458,7 @@ const SelectFieldRoot = React.forwardRef<View, SelectFieldProps>(
447
458
  ref={searchInputRef}
448
459
  value={searchQuery}
449
460
  onChangeText={setSearchQuery}
461
+ onBlur={handleSearchBlur}
450
462
  placeholder={searchPlaceholder ?? "Search..."}
451
463
  returnKeyType="search"
452
464
  clearButtonMode="never"