📌fix: QSelectBox 컴포넌트 닫기 이벤트 추가
- 아웃사이드 클릭시 handleClose 함수 실행하게 코드 수정
This commit is contained in:
parent
9ab38ec8af
commit
a4af0dc006
@ -13,6 +13,7 @@
|
|||||||
"ag-grid-react": "^32.0.2",
|
"ag-grid-react": "^32.0.2",
|
||||||
"axios": "^1.7.8",
|
"axios": "^1.7.8",
|
||||||
"chart.js": "^4.4.6",
|
"chart.js": "^4.4.6",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"fabric": "^5.3.0",
|
"fabric": "^5.3.0",
|
||||||
"framer-motion": "^11.2.13",
|
"framer-motion": "^11.2.13",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
@ -32,12 +33,12 @@
|
|||||||
"react-icons": "^5.3.0",
|
"react-icons": "^5.3.0",
|
||||||
"react-loading-skeleton": "^3.5.0",
|
"react-loading-skeleton": "^3.5.0",
|
||||||
"react-responsive-modal": "^6.4.2",
|
"react-responsive-modal": "^6.4.2",
|
||||||
|
"react-select": "^5.8.1",
|
||||||
"recoil": "^0.7.7",
|
"recoil": "^0.7.7",
|
||||||
"sweetalert2": "^11.14.1",
|
"sweetalert2": "^11.14.1",
|
||||||
"sweetalert2-react-content": "^5.0.7",
|
"sweetalert2-react-content": "^5.0.7",
|
||||||
"uuid": "^10.0.0",
|
"usehooks-ts": "^3.1.0",
|
||||||
"dayjs": "^1.11.13",
|
"uuid": "^10.0.0"
|
||||||
"react-select": "^5.8.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@turf/turf": "^7.0.0",
|
"@turf/turf": "^7.0.0",
|
||||||
|
|||||||
@ -1,21 +1,29 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { useOnClickOutside } from 'usehooks-ts'
|
||||||
|
|
||||||
export default function QSelectBox({ title = '', options, onChange, value, disabled = false, params = {} }) {
|
export default function QSelectBox({ title = '', options, onChange, value, disabled = false, params = {} }) {
|
||||||
const [openSelect, setOpenSelect] = useState(false)
|
const [openSelect, setOpenSelect] = useState(false)
|
||||||
const [selected, setSelected] = useState(title === '' ? options[0].name : title)
|
const [selected, setSelected] = useState(title === '' ? options[0].name : title)
|
||||||
|
const ref = useRef(null)
|
||||||
|
|
||||||
const handleClickSelectOption = (option) => {
|
const handleClickSelectOption = (option) => {
|
||||||
setSelected(option.name)
|
setSelected(option.name)
|
||||||
onChange?.(option, params)
|
onChange?.(option, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setOpenSelect(false)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
value && handleClickSelectOption(value)
|
value && handleClickSelectOption(value)
|
||||||
}, [value])
|
}, [value])
|
||||||
|
|
||||||
|
useOnClickOutside(ref, handleClose)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`sort-select ${openSelect ? 'active' : ''}`} onClick={disabled ? () => {} : () => setOpenSelect(!openSelect)}>
|
<div className={`sort-select ${openSelect ? 'active' : ''}`} ref={ref} onClick={disabled ? () => {} : () => setOpenSelect(!openSelect)}>
|
||||||
<p>{selected}</p>
|
<p>{selected}</p>
|
||||||
<ul className="select-item-wrap">
|
<ul className="select-item-wrap">
|
||||||
{options?.map((option, index) => (
|
{options?.map((option, index) => (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user