From c7ad7d376116f2be84301c1f59574fded0d335dd Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Thu, 9 Jan 2025 01:53:05 -0800 Subject: [PATCH] fix dropdown --- .../void/browser/react/src/util/inputs.tsx | 270 +++++++++--------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx index cccc99cb..15d3c48c 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx @@ -201,153 +201,153 @@ export const VoidCheckBox = ({ label, value, onClick, className }: { label: stri export const VoidCustomSelectBox = ({ - options, - selectedOption, - onChangeOption, - getOptionName, - getOptionsEqual, - className, - arrowTouchesText = true, + options, + selectedOption, + onChangeOption, + getOptionName, + getOptionsEqual, + className, + arrowTouchesText = true, }: { - options: T[]; - selectedOption?: T; - onChangeOption: (newValue: T) => void; - getOptionName: (option: T) => string; - getOptionsEqual: (a: T, b: T) => boolean; - className?: string; - arrowTouchesText?: boolean; + options: T[]; + selectedOption?: T; + onChangeOption: (newValue: T) => void; + getOptionName: (option: T) => string; + getOptionsEqual: (a: T, b: T) => boolean; + className?: string; + arrowTouchesText?: boolean; }) => { - const [isOpen, setIsOpen] = useState(false); - const [position, setPosition] = useState({ top: 0, left: 0 }); - const containerRef = useRef(null); - const buttonRef = useRef(null); + const [isOpen, setIsOpen] = useState(false); + const [position, setPosition] = useState({ top: 0, left: 0 }); + const containerRef = useRef(null); + const buttonRef = useRef(null); - if (!selectedOption) { - selectedOption = options[0]; - } + if (!selectedOption) { + selectedOption = options[0]; + } - const updatePosition = () => { - if (!buttonRef.current) return; - const rect = buttonRef.current.getBoundingClientRect(); - const viewportHeight = window.innerHeight; - const spaceBelow = viewportHeight - rect.bottom; - const spaceNeeded = options.length * 28; // Approximate height per option - const showAbove = spaceBelow < spaceNeeded && rect.top > spaceBelow; + const updatePosition = () => { + if (!buttonRef.current) return; + const rect = buttonRef.current.getBoundingClientRect(); + const viewportHeight = window.innerHeight; + const spaceBelow = viewportHeight - rect.bottom; + const spaceNeeded = options.length * 28; // Approximate height per option + const showAbove = spaceBelow < spaceNeeded && rect.top > spaceBelow; - setPosition({ - top: showAbove ? rect.top - 4 - spaceNeeded : rect.bottom + 4, - left: rect.left, - }); - }; + setPosition({ + top: showAbove ? rect.top - 4 - spaceNeeded : rect.bottom + 4, + left: rect.left, + }); + }; - useEffect(() => { - if (isOpen) { - updatePosition(); - window.addEventListener('scroll', updatePosition, true); - window.addEventListener('resize', updatePosition); + useEffect(() => { + if (isOpen) { + updatePosition(); + window.addEventListener('scroll', updatePosition, true); + window.addEventListener('resize', updatePosition); - return () => { - window.removeEventListener('scroll', updatePosition, true); - window.removeEventListener('resize', updatePosition); - }; - } - }, [isOpen]); + return () => { + window.removeEventListener('scroll', updatePosition, true); + window.removeEventListener('resize', updatePosition); + }; + } + }, [isOpen]); - useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (containerRef.current && !containerRef.current.contains(event.target as Node)) { - setIsOpen(false); - } - }; + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (containerRef.current && !containerRef.current.contains(event.target as Node)) { + setIsOpen(false); + } + }; - if (isOpen) { - document.addEventListener('mousedown', handleClickOutside); - return () => document.removeEventListener('mousedown', handleClickOutside); - } - }, [isOpen]); + if (isOpen) { + document.addEventListener('mousedown', handleClickOutside); + return () => document.removeEventListener('mousedown', handleClickOutside); + } + }, [isOpen]); - return ( -
- {/* Select Button */} - + return ( +
+ {/* Select Button */} + - {/* Dropdown Menu */} - {isOpen && ( -
- {options.map((option) => { - const thisOptionIsSelected = getOptionsEqual(option, selectedOption); - const optionName = getOptionName(option); + {/* Dropdown Menu */} + {isOpen && ( +
+ {options.map((option) => { + const thisOptionIsSelected = getOptionsEqual(option, selectedOption); + const optionName = getOptionName(option); - return ( -
{ - onChangeOption(option); - setIsOpen(false); - }} - > -
- {thisOptionIsSelected && ( - - - - )} -
- {optionName} -
- ); - })} -
- )} -
- ); + return ( +
{ + onChangeOption(option); + setIsOpen(false); + }} + > +
+ {thisOptionIsSelected && ( + + + + )} +
+ {optionName} +
+ ); + })} +
+ )} +
+ ); };