File tree Expand file tree Collapse file tree 5 files changed +33
-55
lines changed Expand file tree Collapse file tree 5 files changed +33
-55
lines changed Original file line number Diff line number Diff line change 11import React from "react"
2- import Drop from "@/components/drops/drop"
3- import Options from "./options"
2+ import { StyledOptionsContainer } from "./styled"
3+ import Dropdown from "@/components/drops/menu/dropdown"
4+ import DropdownItem from "@/components/drops/menu/dropdownItem"
45import useAutocomplete from "./useAutocomplete"
56
6- const Autocomplete = ( { value, autocompleteProps, tagretRef } ) => {
7- const { autocompleteOpen, suggestions } = useAutocomplete ( { value, autocompleteProps } )
7+ const Autocomplete = ( { value, autocompleteProps, Item = DropdownItem } ) => {
8+ const { autocompleteOpen, suggestions, onItemClick } = useAutocomplete ( {
9+ value,
10+ autocompleteProps,
11+ } )
812
913 return (
10- autocompleteOpen &&
11- tagretRef ?. current && (
12- < Drop
13- width = { 60 }
14- target = { tagretRef . current }
15- align = { { top : "bottom" , left : "left" } }
16- animation
17- background = "inputBg"
18- margin = { [ 1 , 0 , 0 ] }
19- round = { 1 }
20- close = { ( ) => { } }
21- onClickOutside = { ( ) => { } }
22- onEsc = { ( ) => { } }
23- >
24- < Options suggestions = { suggestions } />
25- </ Drop >
14+ autocompleteOpen && (
15+ < StyledOptionsContainer >
16+ < Dropdown items = { suggestions } Item = { Item } onItemClick = { onItemClick } width = "100%" />
17+ </ StyledOptionsContainer >
2618 )
2719 )
2820}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import styled from "styled-components"
2+ import Flex from "@/components/templates/flex"
23
3- export const StyledOption = styled . li `
4- &:hover {
5- background-color: red;
6- }
7-
8- &:focus {
9- background-color: red;
10- }
4+ export const StyledOptionsContainer = styled ( Flex ) `
5+ width: 300px;
6+ position: absolute;
7+ left: 0;
8+ top: 36px;
119`
Original file line number Diff line number Diff line change 1+ import { useCallback } from "react"
12import { useState , useEffect } from "react"
23
34const useAutocomplete = ( { value, autocompleteProps = { } } = { } ) => {
45 const [ autocompleteOpen , setAutocompleteOpen ] = useState ( )
56 const { suggestions = [ ] } = autocompleteProps || { }
67
8+ const onItemClick = useCallback ( e => console . log ( e ) , [ ] )
9+
710 useEffect ( ( ) => {
811 if ( suggestions . length ) {
912 setAutocompleteOpen ( ! ! value . length )
1013 }
1114 } , [ suggestions , value , setAutocompleteOpen ] )
1215
13- return { autocompleteOpen, suggestions }
16+ return { autocompleteOpen, suggestions, onItemClick }
1417}
1518
1619export default useAutocomplete
Original file line number Diff line number Diff line change 1- import React , { useRef , useMemo } from "react"
1+ import React , { useMemo } from "react"
22import Flex from "@/components/templates/flex"
33import { TextMicro } from "@/components/typography"
44import { Input , LabelText } from "./styled"
@@ -36,8 +36,6 @@ export const TextInput = ({
3636 autocompleteProps,
3737 ...props
3838} ) => {
39- const inputContainerRef = useRef ( )
40-
4139 const autocompleteInputProps = useMemo (
4240 ( ) =>
4341 autocompleteProps
@@ -50,9 +48,16 @@ export const TextInput = ({
5048 )
5149
5250 return (
53- < Flex gap = { 0.5 } column className = { className } { ...containerStyles } as = "label" >
51+ < Flex
52+ gap = { 0.5 }
53+ column
54+ className = { className }
55+ position = "relative"
56+ { ...containerStyles }
57+ as = "label"
58+ >
5459 { typeof label === "string" ? < LabelText size = { size } > { label } </ LabelText > : label }
55- < Flex ref = { inputContainerRef } position = "relative" { ...inputContainerStyles } >
60+ < Flex position = "relative" { ...inputContainerStyles } >
5661 { iconLeft && (
5762 < Flex position = "absolute" left = { 1 } top = { 0 } bottom = { 0 } alignItems = "center" >
5863 { iconLeft }
@@ -87,11 +92,7 @@ export const TextInput = ({
8792 </ Flex >
8893 { typeof hint === "string" ? < TextMicro color = "textLite" > { hint } </ TextMicro > : ! ! hint && hint }
8994 { ! hideErrorMessage ? < Error error = { error } /> : null }
90- < Autocomplete
91- value = { value }
92- autocompleteProps = { autocompleteProps }
93- tagretRef = { inputContainerRef }
94- />
95+ < Autocomplete value = { value } autocompleteProps = { autocompleteProps } />
9596 </ Flex >
9697 )
9798}
You can’t perform that action at this time.
0 commit comments