@faststore/ui 1.5.12 → 1.5.15

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": "@faststore/ui",
3
- "version": "1.5.12",
3
+ "version": "1.5.15",
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.12",
79
+ "@vtex/theme-b2c-tailwind": "^1.5.15",
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": "dd487ecb27c59bd1136c44cb2271cc3eea34aa30"
92
+ "gitHead": "85a78b7c1d0c7b779c25d55364c174e9d8e9e48f"
93
93
  }
package/src/index.ts CHANGED
@@ -58,7 +58,7 @@ export { default as Bullets } from './molecules/Bullets'
58
58
  export type { BulletsProps } from './molecules/Bullets'
59
59
 
60
60
  export { default as SearchInput } from './molecules/SearchInput'
61
- export type { SearchInputProps } from './molecules/SearchInput'
61
+ export type { SearchInputProps, SearchInputRef } from './molecules/SearchInput'
62
62
 
63
63
  export { default as Carousel } from './molecules/Carousel'
64
64
  export type { CarouselProps } from './molecules/Carousel'
@@ -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
- const SearchInput = forwardRef<HTMLFormElement, SearchInputProps>(
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 valueRef = useRef<HTMLInputElement>(null)
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 (valueRef.current?.value !== '') {
70
- onSubmit(valueRef.current!.value)
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={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={valueRef} aria-label={ariaLabel} {...otherProps} />
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>
@@ -1,2 +1,2 @@
1
1
  export { default } from './SearchInput'
2
- export type { SearchInputProps } from './SearchInput'
2
+ export type { SearchInputProps, SearchInputRef } from './SearchInput'