Skip to content

Commit

Permalink
fix: focus blur
Browse files Browse the repository at this point in the history
  • Loading branch information
aswathy-deriv committed Mar 1, 2024
1 parent 6fa0c42 commit 068a99f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/elements/dropdown-search.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import styled, { css } from 'styled-components'
import { Placeholder } from 'gatsby-plugin-image'
import {
Arrow,
BottomLabel,
Expand Down Expand Up @@ -86,8 +85,13 @@ const DropdownSearch = ({
}: DropdownProps) => {
const [input_value, setInputValue] = useState('')
const [dropdown_items, setDropdownItems] = useState([...items])
const [is_open, dropdown_ref, nodes, handleChange, toggleListVisibility, setOpen] =
const [is_open, dropdown_ref, nodes, handleChange, toggleListVisibility, setOpen, closeFocus] =
useDropdown(onChange)
const inputRef = useRef(null)

useEffect(() => {
!is_open && inputRef.current.blur()
}, [is_open])

// Auto select default value
useEffect(() => {
Expand Down Expand Up @@ -144,6 +148,7 @@ const DropdownSearch = ({
</StyledLabel>
<DropdownInput
id="selected_dropdown"
ref={inputRef}
tabIndex={0}
onClick={toggleListVisibility}
onChange={handleInputChange}
Expand Down

0 comments on commit 068a99f

Please sign in to comment.