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.

isSelected not working

See original GitHub issue

I am trying to change the font weight to bold when option is being selected but isSelected is not working. Here is the codesandbox link https://codesandbox.io/s/react-codesandboxer-example-9gpp4

I try to debug it with react-devtools it’s not getting isFocused isDisabled and everything else but not isSelected is not there.

Props

{
  "value": {
    "label": "Off Trade",
    "value": "offTrade",
    "id": 2,
    "questionKey": 3
  },
  "options": [
    "Object",
    "Object",
    "Object",
    "Object"
  ],
  "styles": {
    "control": "control()",
    "option": "option()",
    "indicatorSeparator": "indicatorSeparator()",
    "dropdownIndicator": "dropdownIndicator()"
  },
  "onChange": "fn()",
  "inputValue": "",
  "menuIsOpen": false,
  "onInputChange": "fn()",
  "onMenuClose": "fn()",
  "onMenuOpen": "fn()",
  "backspaceRemovesValue": true,
  "blurInputOnSelect": false,
  "captureMenuScroll": true,
  "closeMenuOnSelect": true,
  "closeMenuOnScroll": false,
  "components": {},
  "controlShouldRenderValue": true,
  "escapeClearsValue": false,
  "filterOption": "fn()",
  "formatGroupLabel": "formatGroupLabel()",
  "getOptionLabel": "getOptionLabel()",
  "getOptionValue": "getOptionValue()",
  "isDisabled": false,
  "isLoading": false,
  "isMulti": false,
  "isRtl": false,
  "isSearchable": true,
  "isOptionDisabled": "isOptionDisabled()",
  "loadingMessage": "loadingMessage()",
  "maxMenuHeight": 300,
  "minMenuHeight": 140,
  "menuPlacement": "bottom",
  "menuPosition": "absolute",
  "menuShouldBlockScroll": false,
  "menuShouldScrollIntoView": true,
  "noOptionsMessage": "noOptionsMessage()",
  "openMenuOnFocus": false,
  "openMenuOnClick": true,
  "pageSize": 5,
  "placeholder": "Select...",
  "screenReaderStatus": "screenReaderStatus()",
  "tabIndex": "0",
  "tabSelectsValue": true
}

State

{
  "ariaLiveSelection": "option Off Trade, selected.",
  "ariaLiveContext": "Select is focused ,type to refine list, press Down to open the menu, ",
  "focusedValue": null,
  "inputIsHidden": false,
  "isFocused": false,
  "menuOptions": {
    "render": "Array[0]",
    "focusable": "Array[0]"
  },
  "selectValue": [
    {
      "label": "Off Trade",
      "value": "offTrade",
      "id": 2,
      "questionKey": 3
    }
  ]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
luksaricommented, Jan 9, 2020

I suppose that isSelected property doesn’t exist in Select not marked as isMultiple. So you can use state.data === state.selectProps.value in single choice Select to apply different style based on state.
Example:

 option: (provided, state) => {
    return ({
      ...provided,
      color: state.data === state.selectProps.value ? `${theme.colors.primaryText}` : `${theme.colors.disabledText}`,
      '&:hover': {
        color: theme.colors.primaryText,
        background: theme.colors.disabledBackground,
      },
    });
  },```
2reactions
crhayescommented, Oct 29, 2019

@sarabs3 You can inspect the contents of state to see if there is anything useful for your use case.

isSelected exists in the option state but not in the control state, which I think makes, given that the options are what are actually selected.

If you inspect the state in the control method you’ll see the property hasValue. That should work for your use case:

control: (styles, state) => ({
  ...styles,
  fontSize: state.hasValue ? 40 : 20
})

image

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

isSelected() method for checkbox always returns false
In my view, isSelected() returns true only if it is a default selection. It may not work when we select an element and...
Read more >
isselected() method returning false always why?
First, I want to check whether checkbox is selected or not and then have to perform select action. But here ...
Read more >
isSelected() method for checkbox always returns false on ...
Hello Everyone,In this video, i am going to discuss about the issue " isSelected () method for checkbox always returns false on selenium ......
Read more >
isSelected | Apple Developer Documentation
A Boolean value that indicates whether the cell is selected.
Read more >
The isSelected() method - Selenium WebDriver 3 Practical ...
The isSelected() method The isSelected method returns a boolean value if an element is selected on the web page and can be executed...
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