Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-4722: close drop down (#1028) #1029

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions components/modal/registration/institution-select.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect, useRef } from 'react'
import { TextField } from '@oacore/design'

import styles from './styles.module.scss'
Expand All @@ -10,6 +10,7 @@ const DropdownInput = ({
organisationNameSuggestions,
}) => {
const [isOpen, setIsOpen] = useState(false)
const dropdownRef = useRef(null)

const handleInputChange = (event) => {
bindOrganisationName.onChange(event)
Expand All @@ -23,8 +24,21 @@ const DropdownInput = ({

const hasValue = !!bindOrganisationName.value

const handleClickOutside = (event) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target))
setIsOpen(false)
}

useEffect(() => {
document.addEventListener('click', handleClickOutside)

return () => {
document.removeEventListener('click', handleClickOutside)
}
}, [])

return (
<div className={styles.dropdownInput}>
<div className={styles.dropdownInput} ref={dropdownRef}>
<TextField
id={elemOrganisationName}
name={elemOrganisationName}
Expand Down
Loading