@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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__mocks__/react-native.tsx +2 -0
- package/src/components/molecules/SelectField/SelectField.test.tsx +18 -0
- package/src/components/molecules/SelectField/SelectField.tsx +12 -0
package/package.json
CHANGED
|
@@ -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"
|