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

Commit 6cbc10a

Browse files
authored
fix(Accordion|Dropdown): fix default props in auto controlled mode (#675)
fix(Accordion|Dropdown): fix default props in auto controlled mode
1 parent 4b684e5 commit 6cbc10a

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2424
### Fixes
2525
- Fix unicode arrow characters to be RTL aware ([#690](https://github.com/stardust-ui/react/pull/690))
2626
- Fix positioning of `Popup` with changable content @layershifter ([#678](https://github.com/stardust-ui/react/pull/678))
27+
- Fix default props in `Accordion` and `Dropdown` components @layershifter ([#675](https://github.com/stardust-ui/react/pull/675))
2728

2829
<!--------------------------------[ v0.16.0 ]------------------------------- -->
2930
## [v0.16.0](https://github.com/stardust-ui/react/tree/v0.16.0) (2019-01-07)

docs/src/examples/components/Accordion/Types/AccordionExample.shorthand.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ const panels = [
1414
},
1515
]
1616

17-
const AccordionExample = () => <Accordion panels={panels} />
17+
const AccordionExample = () => <Accordion defaultActiveIndex={[0]} panels={panels} />
1818

1919
export default AccordionExample

docs/src/examples/components/Accordion/Variations/AccordionExampleList.shorthand.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AccordionExampleList extends React.Component {
1818
},
1919
]
2020

21-
return <Accordion panels={panels} />
21+
return <Accordion defaultActiveIndex={[0]} panels={panels} />
2222
}
2323
}
2424

src/components/Accordion/Accordion.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ class Accordion extends AutoControlledComponent<ReactProps<AccordionProps>, any>
118118
static Title = AccordionTitle
119119
static Content = AccordionContent
120120

121-
state: any = { activeIndex: [0] }
122-
123121
getInitialAutoControlledState({ exclusive }) {
124122
return { activeIndex: exclusive ? -1 : [-1] }
125123
}

src/components/Dropdown/Dropdown.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ export default class Dropdown extends AutoControlledComponent<
194194
static Label = DropdownLabel
195195
static SearchInput = DropdownSearchInput
196196

197-
state: DropdownState = {
198-
// prevent deletion of last character + last selected value at the same time on backspace.
199-
backspaceDelete: this.props.multiple,
200-
focused: false,
201-
searchQuery: this.props.search ? '' : undefined,
202-
value: this.props.multiple ? [] : null,
197+
getInitialAutoControlledState({ multiple, search }: DropdownProps): DropdownState {
198+
return {
199+
// prevent deletion of last character + last selected value at the same time on backspace.
200+
backspaceDelete: multiple,
201+
focused: false,
202+
searchQuery: search ? '' : undefined,
203+
value: multiple ? [] : null,
204+
}
203205
}
204206

205207
public renderComponent({

0 commit comments

Comments
 (0)