Skip to content

Close menu when last element is selected #157

Answered by csandman
dz3n asked this question in Q&A
Discussion options

You must be logged in to vote

Hmm, I gave this some thought but there's no built in way to do this (as far as I know). However, it can be accomplished pretty easily by attaching a ref to the select component and running a .blur() followed by a .focus() when all options are selected. This works because the .focus() method doesn't open the list of options, just focuses the input. However, if you don't care about the input being focused after, you can just drop that part. Here's a basic example of how you could accomplish that:

import { useState, useRef, useEffect } from "react";
import { Select } from "chakra-react-select";
import { colorOptions } from "./data/data";

const FlatOptionsExample = () => {
  const [selected…

Replies: 1 comment 1 reply

Comment options

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

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