Skip to content

Can a combobox also be used to specify a value not in the default list? #3093

Answered by laurenfb
laurenfb asked this question in General
Discussion options

You must be logged in to vote

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);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SiTaggart
Comment options

Answer selected by nkrantz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants