mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 02:10:12 -06:00
Merge branch 'main' of https://github.com/formbricks/formbricks into feat-resetpassword
This commit is contained in:
@@ -21,16 +21,27 @@ export const OptionsSwitch = ({
|
||||
const [highlightStyle, setHighlightStyle] = useState({});
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (containerRef.current) {
|
||||
const activeElement = containerRef.current.querySelector(`[data-value="${currentOption}"]`);
|
||||
if (activeElement) {
|
||||
const { offsetLeft, offsetWidth } = activeElement as HTMLElement;
|
||||
setHighlightStyle({
|
||||
left: `${offsetLeft}px`,
|
||||
width: `${offsetWidth}px`,
|
||||
});
|
||||
const updateHighlight = () => {
|
||||
if (containerRef.current) {
|
||||
const activeElement = containerRef.current.querySelector(`[data-value="${currentOption}"]`);
|
||||
if (activeElement) {
|
||||
const { offsetLeft, offsetWidth } = activeElement as HTMLElement;
|
||||
setHighlightStyle({
|
||||
left: `${offsetLeft}px`,
|
||||
width: `${offsetWidth}px`,
|
||||
});
|
||||
} else {
|
||||
// Hide highlight if no matching element found
|
||||
setHighlightStyle({ opacity: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// Initial call
|
||||
updateHighlight();
|
||||
|
||||
// Listen to resize
|
||||
window.addEventListener("resize", updateHighlight);
|
||||
return () => window.removeEventListener("resize", updateHighlight);
|
||||
}, [currentOption]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user