diff --git a/src/shared/components/TagInput.js b/src/shared/components/TagInput.js index f432567..cdd6495 100644 --- a/src/shared/components/TagInput.js +++ b/src/shared/components/TagInput.js @@ -1,6 +1,7 @@ 'use client'; import { useState, useRef, useEffect } from 'react'; +import { createPortal } from 'react-dom'; const hexToRgb = (hex) => { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); @@ -53,6 +54,7 @@ const TagInput = ({ }) => { const [inputValue, setInputValue] = useState(''); const [isOpen, setIsOpen] = useState(false); + const [dropdownStyle, setDropdownStyle] = useState({}); const containerRef = useRef(null); const inputRef = useRef(null); @@ -72,6 +74,23 @@ const TagInput = ({ return () => document.removeEventListener('mousedown', handleClickOutside); }, []); + useEffect(() => { + if (!isOpen || !containerRef.current) return; + const updatePosition = () => { + const rect = containerRef.current?.getBoundingClientRect(); + if (rect) { + setDropdownStyle({ top: rect.bottom + 6, left: rect.left, width: rect.width }); + } + }; + updatePosition(); + window.addEventListener('scroll', updatePosition, true); + window.addEventListener('resize', updatePosition); + return () => { + window.removeEventListener('scroll', updatePosition, true); + window.removeEventListener('resize', updatePosition); + }; + }, [isOpen]); + const selectOption = (option) => { onChange([...value, option.value]); setInputValue(''); @@ -124,8 +143,8 @@ const TagInput = ({ className="flex-1 min-w-[80px] bg-transparent outline-none text-neutral-900 dark:text-white placeholder-neutral-400 dark:placeholder-neutral-500 text-sm" /> - {isOpen && filtered.length > 0 && ( -
Aucun résultat
-