Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(Dropdown): fix switch between multiple and single modes #1830

Merged
merged 5 commits into from
Aug 21, 2019

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Aug 20, 2019

Fixes #1658.

Fix 🔧

Previously, we had value in the Dropdown's state that conditionally can be single item or array of items. This PR performs normalization of values, so we will always deal with array of items. This allows to remove a lot of type casts and conditions.

A code snippet to test
import React from 'react'
import { Checkbox, Dropdown } from '@stardust-ui/react'

const inputItems = [
  'Bruce Wayne',
  'Natasha Romanoff',
  'Steven Strange',
  'Alfred Pennyworth',
  `Scarlett O'Hara`,
  'Imperator Furiosa',
  'Bruce Banner',
  'Peter Parker',
  'Selina Kyle',
]

const DropdownExample = () => {
  const [search, setSearch] = React.useState(false)
  const [multiple, setMultiple] = React.useState(false)

  return (
    <>
      <Dropdown items={inputItems} multiple={multiple} search={search} />
      <Checkbox
        checked={multiple}
        label="multiple"
        onChange={(e, props) => setMultiple(props.checked)}
      />
      <Checkbox checked={search} label="search" onChange={(e, props) => setSearch(props.checked)} />
    </>
  )
}

export default DropdownExample

@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #1830 into master will increase coverage by 0.01%.
The diff coverage is 97.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1830      +/-   ##
==========================================
+ Coverage   69.52%   69.53%   +0.01%     
==========================================
  Files         875      875              
  Lines        7609     7590      -19     
  Branches     2225     2210      -15     
==========================================
- Hits         5290     5278      -12     
+ Misses       2311     2304       -7     
  Partials        8        8
Impacted Files Coverage Δ
...ackages/react/src/components/Dropdown/Dropdown.tsx 88.04% <97.43%> (-0.18%) ⬇️
...rc/themes/teams/components/Alert/alertVariables.ts 0% <0%> (ø) ⬆️
...test/specs/commonTests/implementsShorthandProp.tsx 100% <0%> (ø) ⬆️
...t/src/themes/teams/components/Alert/alertStyles.ts 7.69% <0%> (+0.54%) ⬆️
packages/react/src/lib/renderComponent.tsx 86.44% <0%> (+1.19%) ⬆️
packages/react/src/components/Alert/Alert.tsx 100% <0%> (+20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74cc53e...c254afa. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toggling Multiple/Search/etc. Breaks Dropdown
2 participants