Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DropDownMenu] Display the first item in case there's no one with the corresponding value #4822

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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