From 787fe765af5077aa9a94277d84fd942b6a063377 Mon Sep 17 00:00:00 2001 From: Julien Saguez Date: Tue, 4 Feb 2025 15:48:00 +0100 Subject: [PATCH 1/3] feat(searchinput): add value prop for initial value --- .changeset/eleven-penguins-tell.md | 5 +++++ packages/ui/src/components/SearchInput/index.tsx | 3 ++- packages/ui/src/components/SearchInput/types.ts | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/eleven-penguins-tell.md diff --git a/.changeset/eleven-penguins-tell.md b/.changeset/eleven-penguins-tell.md new file mode 100644 index 0000000000..e9384e03fc --- /dev/null +++ b/.changeset/eleven-penguins-tell.md @@ -0,0 +1,5 @@ +--- +"@ultraviolet/ui": minor +--- + +add `value` prop for initial value of searchinput diff --git a/packages/ui/src/components/SearchInput/index.tsx b/packages/ui/src/components/SearchInput/index.tsx index 1baf456ed7..b80021d3a1 100644 --- a/packages/ui/src/components/SearchInput/index.tsx +++ b/packages/ui/src/components/SearchInput/index.tsx @@ -86,13 +86,14 @@ export const SearchInput = forwardRef( autoComplete, onKeyDown, role, + value, }: SearchInputProps, ref: Ref, ) => { const focusedLinkIndex = useRef(0) const popupRef = useRef(null) const [containerWidth, setContainerWidth] = useState(0) - const [searchTerms, setSearchTerms] = useState('') + const [searchTerms, setSearchTerms] = useState(value || '') const [isMacOS, setIsMacOS] = useState(false) const [keyPressed, setKeyPressed] = useState([]) const [isOpen, toggleIsOpen] = useReducer(state => !state, false) diff --git a/packages/ui/src/components/SearchInput/types.ts b/packages/ui/src/components/SearchInput/types.ts index 6313bc133b..6d8f5a9edf 100644 --- a/packages/ui/src/components/SearchInput/types.ts +++ b/packages/ui/src/components/SearchInput/types.ts @@ -37,5 +37,4 @@ export type SearchInputProps = { | 'onRandomize' | 'onChange' | 'type' - | 'value' > From fc03fa5a2907a888d665cda2f70f212ea0f7e78a Mon Sep 17 00:00:00 2001 From: Julien Saguez Date: Tue, 4 Feb 2025 16:17:36 +0100 Subject: [PATCH 2/3] feat(searchinput): add initialValue prop for initial value and value for change value locally --- .changeset/eleven-penguins-tell.md | 2 +- packages/ui/src/components/SearchInput/index.tsx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.changeset/eleven-penguins-tell.md b/.changeset/eleven-penguins-tell.md index e9384e03fc..f5571de44a 100644 --- a/.changeset/eleven-penguins-tell.md +++ b/.changeset/eleven-penguins-tell.md @@ -2,4 +2,4 @@ "@ultraviolet/ui": minor --- -add `value` prop for initial value of searchinput +add `initialValue` prop for initial value and `value` for change value locally of searchinput diff --git a/packages/ui/src/components/SearchInput/index.tsx b/packages/ui/src/components/SearchInput/index.tsx index b80021d3a1..ad708911ae 100644 --- a/packages/ui/src/components/SearchInput/index.tsx +++ b/packages/ui/src/components/SearchInput/index.tsx @@ -68,6 +68,7 @@ export const SearchInput = forwardRef( 'data-testid': dataTestId, shortcut = false, error, + defaultValue = '', disabled, className, minLength, @@ -93,7 +94,7 @@ export const SearchInput = forwardRef( const focusedLinkIndex = useRef(0) const popupRef = useRef(null) const [containerWidth, setContainerWidth] = useState(0) - const [searchTerms, setSearchTerms] = useState(value || '') + const [searchTerms, setSearchTerms] = useState(defaultValue) const [isMacOS, setIsMacOS] = useState(false) const [keyPressed, setKeyPressed] = useState([]) const [isOpen, toggleIsOpen] = useReducer(state => !state, false) @@ -156,6 +157,12 @@ export const SearchInput = forwardRef( return () => window.removeEventListener('resize', resizeSearchBar) }, []) + useEffect(() => { + if (value) { + setSearchTerms(value) + } + }, [value]) + const onSearchCallback = (localValue: string) => { setSearchTerms(localValue) From 8a66a16179de1e3de4a7961d952f12f945048504 Mon Sep 17 00:00:00 2001 From: JulienSaguez <136359793+JulienSaguez@users.noreply.github.com> Date: Wed, 5 Feb 2025 10:16:36 +0100 Subject: [PATCH 3/3] Update .changeset/eleven-penguins-tell.md Co-authored-by: radhi-nasser-scaleway --- .changeset/eleven-penguins-tell.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eleven-penguins-tell.md b/.changeset/eleven-penguins-tell.md index f5571de44a..17288fff8e 100644 --- a/.changeset/eleven-penguins-tell.md +++ b/.changeset/eleven-penguins-tell.md @@ -2,4 +2,4 @@ "@ultraviolet/ui": minor --- -add `initialValue` prop for initial value and `value` for change value locally of searchinput +add `defaultValue` prop for initial value and `value` for change value locally of searchinput