-
Hi Paste, as per this earlier discussion, #3080 (comment), we are using a Combobox for a font size selector. One requested feature is the ability to type a non-listed font size (23, for instance). Is it possible/advisable to use a Combobox in this way? Should we wrap it in a Form, or is there another way that we can use an I haven't seen anything similar in a search of previous discussions, which surprises me, so it makes me wonder if this case is inadvisable or not permitted. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, just an update for anyone looking at this later on, here is how we solved this (unless there is a better way). const comboboxRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (comboboxRef && comboboxRef.current) {
comboboxRef.current.addEventListener('keypress', handleKeyPress);
const refClosure = comboboxRef.current;
return () => refClosure.removeEventListener('keypress', handleKeyPress);
}
}, [comboboxRef, handleKeyPress]);
const handleKeyPress = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Enter' && e.target) {
e.preventDefault();
const { value } = e.target as HTMLInputElement;
applyFontSize(value);
}
},
[applyFontSize],
); <Combobox ref={comboboxRef} (and other props)/> |
Beta Was this translation helpful? Give feedback.
Hi, just an update for anyone looking at this later on, here is how we solved this (unless there is a better way).