@faststore/ui 1.5.9 → 1.5.13
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/CHANGELOG.md +44 -0
- package/dist/molecules/SearchInput/SearchInput.d.ts +5 -1
- package/dist/ui.cjs.development.js +11 -6
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +12 -7
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/molecules/SearchInput/SearchInput.tsx +18 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
4
4
|
"description": "A lightweight, framework agnostic component library for React",
|
|
5
5
|
"author": "emersonlaurentino",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@types/jest-axe": "^3.5.3",
|
|
77
77
|
"@types/tabbable": "^3.1.1",
|
|
78
78
|
"@types/testing-library__jest-dom": "^5.9.5",
|
|
79
|
-
"@vtex/theme-b2c-tailwind": "^1.5.
|
|
79
|
+
"@vtex/theme-b2c-tailwind": "^1.5.13",
|
|
80
80
|
"@vtex/tsconfig": "^0.5.0",
|
|
81
81
|
"chalk": "^5.0.0",
|
|
82
82
|
"jest-axe": "^5.0.1",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"tsdx": "^0.14.1",
|
|
90
90
|
"typescript": "^4.2.4"
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "81bc636d76a0da11f10835bfc48f4e44329e4ce2"
|
|
93
93
|
}
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
InputHTMLAttributes,
|
|
5
5
|
ReactNode,
|
|
6
6
|
} from 'react'
|
|
7
|
-
import React, { forwardRef, useRef } from 'react'
|
|
7
|
+
import React, { useImperativeHandle, forwardRef, useRef } from 'react'
|
|
8
8
|
|
|
9
9
|
import Button from '../../atoms/Button'
|
|
10
10
|
import Icon from '../../atoms/Icon'
|
|
@@ -50,7 +50,12 @@ export interface SearchInputProps extends InputProps {
|
|
|
50
50
|
testId?: string
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
export interface SearchInputRef {
|
|
54
|
+
inputRef?: HTMLInputElement | null
|
|
55
|
+
formRef?: HTMLFormElement | null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const SearchInput = forwardRef<SearchInputRef | null, SearchInputProps>(
|
|
54
59
|
function SearchInput(
|
|
55
60
|
{
|
|
56
61
|
onSubmit,
|
|
@@ -61,25 +66,31 @@ const SearchInput = forwardRef<HTMLFormElement, SearchInputProps>(
|
|
|
61
66
|
},
|
|
62
67
|
ref
|
|
63
68
|
) {
|
|
64
|
-
const
|
|
69
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
70
|
+
const formRef = useRef<HTMLFormElement>(null)
|
|
65
71
|
|
|
66
72
|
const handleSubmit = (event: FormEvent) => {
|
|
67
73
|
event.preventDefault()
|
|
68
74
|
|
|
69
|
-
if (
|
|
70
|
-
onSubmit(
|
|
75
|
+
if (inputRef.current?.value !== '') {
|
|
76
|
+
onSubmit(inputRef.current!.value)
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
useImperativeHandle(ref, () => ({
|
|
81
|
+
inputRef: inputRef.current,
|
|
82
|
+
formRef: formRef.current,
|
|
83
|
+
}))
|
|
84
|
+
|
|
74
85
|
return (
|
|
75
86
|
<Form
|
|
76
|
-
ref={
|
|
87
|
+
ref={formRef}
|
|
77
88
|
data-store-search-input
|
|
78
89
|
data-testid={testId}
|
|
79
90
|
onSubmit={handleSubmit}
|
|
80
91
|
role="search"
|
|
81
92
|
>
|
|
82
|
-
<Input ref={
|
|
93
|
+
<Input ref={inputRef} aria-label={ariaLabel} {...otherProps} />
|
|
83
94
|
<Button type="submit" aria-label="Submit Search">
|
|
84
95
|
<Icon component={icon ?? <SearchIcon />} />
|
|
85
96
|
</Button>
|