question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add state modifiers (like isFocused) to MultiValueRemove component state

See original GitHub issue

Hi, it would be great to have a little more control over the MultiValueRemove component in react-select. Most components get the <component>-is-focused classes applied, but it seems like this one doesn’t. My guess is that it’s slightly more complex than others because of the left/right arrow key navigation to delete selected options, but not having access to these various properties makes it difficult to override the styles.

Here’s the hack I have to resort to for overriding the styles:

Create custom component for MultiValueRemove

const CustomMultiValueRemove = ({ ...props }) => {
  return (
    <components.MultiValueRemove {...props}>
      <span className="multi-value-remove-button">
        <div className="multi-value-remove-icon" />
      </span>
    </components.MultiValueRemove>
  )

Omit the styles from the style function that I want to override

    const styleOverrides = {
      multiValueRemove: (base, state) => ({
        ...omit(base, [':hover', 'color', 'backgroundColor']),
      }),
    }

Not the prettiest solution, since I’m basically nuking the default functionality and injecting my own custom markup just to have more control.

Anyway, let me know if there’s a better way of doing this or if this is planned for the future!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
ebonowcommented, Jan 16, 2021

@Slapbox the issue is mostly semantics at this point as isFocused (or isDisabled) could potentially refer to the specific component or the Select. That is the main reason why it wasn’t originally included in all of the components and it’s likely that a future version will contain something like inputIsFocused to provide more context of what’s focused.

1reaction
Slapboxcommented, Jan 15, 2021

Thanks for your speedy reply @ebonow. I ended up using useState to pass a prop called instanceIsFocused which works great. I should have clarified in my original post, “seemingly impossible with the built-in props.”

I was just surprised it was not possible, since I’d think that tracking overall focus would be built in with how robust the library is. It would be great to have it built-in. Thanks to you and everyone else whose hard work makes this project possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styles - React Select
The second argument is the current state (features like isFocused , isSelected etc). This allows you to implement dynamic styles for each of...
Read more >
Styles - React Select
Each component is keyed, and ships with default styles. ... The second argument is the current state of the select, features like isFocused...
Read more >
react-select-fixed-v2/HISTORY.md - UNPKG
9, * [#3492](https://github.com/JedWatson/react-select/pull/3492) Add labels to fields ... component now also receives the isFocused state value as a prop.
Read more >
State and Province Modifiers : r/hoi4modding - Reddit
I know this is possible, as there are other state modifiers such as "Kemalist ... To add dynamic modifier to a state, you...
Read more >
react multiple option values selected Code Example - Code Grepper
lightweigt multiple select pure react component npm i ... Add a Grepper Answer ... react-select How to update state between multiple select dropdowns ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found