Skip to content

Commit

Permalink
Merge pull request #4822 from zalmoxisus/patch-1
Browse files Browse the repository at this point in the history
[DropDownMenu] Display the first item in case there's no one with the corresponding value
  • Loading branch information
oliviertassinari authored Jul 26, 2016
2 parents 07c1313 + ef888df commit b7599a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/DropDownMenu/DropDownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ class DropDownMenu extends Component {
const {prepareStyles} = this.context.muiTheme;
const styles = getStyles(this.props, this.context);

let displayValue = '';
let displayValue;
React.Children.forEach(children, (child) => {
if (value === child.props.value) {
if (!displayValue || value === child.props.value) {
// This will need to be improved (in case primaryText is a node)
displayValue = child.props.label || child.props.primaryText;
}
Expand Down
14 changes: 13 additions & 1 deletion src/DropDownMenu/DropDownMenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ describe('<DropDownMenu />', () => {

it('displays the text field of menuItems prop at index x when value prop is x', () => {
const wrapper = shallowWithContext(
<DropDownMenu value={1}>
<DropDownMenu value={2}>
<div value={1} primaryText="Never" />
<div value={2} primaryText="Every Night" />
<div value={3} primaryText="Weeknights" />
</DropDownMenu>
);

assert.strictEqual(wrapper.childAt(0).childAt(0).childAt(0).node, 'Every Night');
});

it('displays the text field of the first menuItems prop when value prop isn\'t found', () => {
const wrapper = shallowWithContext(
<DropDownMenu value={4}>
<div value={1} primaryText="Never" />
<div value={2} primaryText="Every Night" />
<div value={3} primaryText="Weeknights" />
Expand Down

0 comments on commit b7599a4

Please sign in to comment.