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

New prop for DropDownMenu: displayMemberOnLabel #2285

Merged
merged 5 commits into from
Nov 27, 2015
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
21 changes: 20 additions & 1 deletion docs/src/app/components/pages/components/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export default class DropDownMenuPage extends React.Component {
desc: 'DropDownMenu will use payload as default value, with this ' +
'property you can choose another name.',
},
{
name: 'labelMember',
type: 'string',
header: 'default: text',
desc: 'DropDownMenu will use text as default value, with this ' +
'property you can choose another name.',
},
{
name: 'autoWidth',
type: 'bool',
Expand Down Expand Up @@ -113,6 +120,13 @@ export default class DropDownMenuPage extends React.Component {
},
];

let menuItemsWithLabel = [
{ payload: '1', text: 'Morning', period: '5 am - 12 pm' },
{ payload: '2', text: 'Afternoon', period: '12 pm - 5 pm' },
{ payload: '3', text: 'Evening', period: '5 pm to 9 pm' },
{ payload: '4', text: 'Night', period: '9 pm to 4 am' },
];

return (
<ComponentDoc
name="Drop Down Menu"
Expand All @@ -128,7 +142,12 @@ export default class DropDownMenuPage extends React.Component {
</Paper>

<CodeExample code={Code}>
<DropDownMenu menuItems={menuItems} />
<DropDownMenu menuItems={menuItems} /><br/>
<DropDownMenu
menuItems={menuItemsWithLabel}
labelMember="period"
/>

</CodeExample>
</ComponentDoc>
);
Expand Down
17 changes: 16 additions & 1 deletion docs/src/app/components/pages/components/select-fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const SelectFieldsPage = React.createClass({
desc: 'SelectField will use text as default value, with this ' +
'property you can choose another name.',
},
{
name: 'labelMember',
type: 'string',
header: 'default: text',
desc: 'DropDownMenu will use text as default value, with this ' +
'property you can choose another name.',
},
{
name: 'errorStyle',
type: 'object',
Expand Down Expand Up @@ -189,7 +196,12 @@ const SelectFieldsPage = React.createClass({
{id:4, name:'Weekends'},
{id:5, name:'Weekly'},
];

let menuItemsWithLabel = [
{ payload: '1', text: 'Morning', period: '5 am - 12 pm' },
{ payload: '2', text: 'Afternoon', period: '12 pm - 5 pm' },
{ payload: '3', text: 'Evening', period: '5 pm to 9 pm' },
{ payload: '4', text: 'Night', period: '9 pm to 4 am' },
];

let styles = this.getStyles();

Expand Down Expand Up @@ -217,6 +229,9 @@ const SelectFieldsPage = React.createClass({
onChange={this._handleSelectValueChange.bind(null, 'selectValue')}
hintText="Hint Text"
menuItems={menuItems} /><br/>
<SelectField
menuItems={menuItemsWithLabel}
labelMember="period" /><br/>
<SelectField
valueLink={this.linkState('selectValueLinkValue')}
floatingLabelText="Float Label Text"
Expand Down
8 changes: 8 additions & 0 deletions docs/src/app/components/raw-code/drop-down-menu-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ let menuItems = [
{ payload: '5', text: 'Weekly' },
];
<DropDownMenu menuItems={menuItems} />

let menuItemsWithLabel = [
{ payload: '1', text: 'Morning', period: '5 am - 12 pm' },
{ payload: '2', text: 'Afternoon', period: '12 pm - 5 pm' },
{ payload: '3', text: 'Evening', period: '5 pm to 9 pm' },
{ payload: '4', text: 'Night', period: '9 pm to 4 am' },
];
<DropDownMenu menuItems={menuItemsWithLabel} labelMember="period" />
3 changes: 3 additions & 0 deletions docs/src/app/components/raw-code/select-fields-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
onChange={this._handleSelectValueChange.bind(null, 'selectValue')}
hintText="Hint Text"
menuItems={menuItems} /><br/>
<SelectField
menuItems={menuItemsWithLabel}
labelMember="period" /><br/>
<SelectField
valueLink={this.linkState('selectValueLinkValue')}
floatingLabelText="Float Label Text"
Expand Down
5 changes: 4 additions & 1 deletion src/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const DropDownMenu = React.createClass({
openImmediately: React.PropTypes.bool,
style: React.PropTypes.object,
value: React.PropTypes.object,
labelMember: React.PropTypes.string,
},

getDefaultProps() {
Expand All @@ -58,6 +59,7 @@ const DropDownMenu = React.createClass({
valueMember: 'payload',
displayMember: 'text',
openImmediately: false,
labelMember: 'text',
};
},

Expand Down Expand Up @@ -186,6 +188,7 @@ const DropDownMenu = React.createClass({
iconStyle,
underlineStyle,
menuItemStyle,
labelMember,
...other,
} = this.props;

Expand All @@ -210,7 +213,7 @@ const DropDownMenu = React.createClass({

let selectedItem = this.props.menuItems[selectedIndex];
if (selectedItem) {
displayValue = selectedItem[displayMember];
displayValue = selectedItem[labelMember];
}

let menuItems = this.props.menuItems.map((item) => {
Expand Down
4 changes: 4 additions & 0 deletions src/select-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const SelectField = React.createClass({
menuItemStyle: React.PropTypes.object,
selectedIndex: React.PropTypes.number,
style: React.PropTypes.object,
labelMember: React.PropTypes.string,
},

//for passing default theme context to children
Expand All @@ -73,6 +74,7 @@ const SelectField = React.createClass({
getDefaultProps() {
return {
fullWidth: false,
labelMember: 'text',
};
},

Expand Down Expand Up @@ -142,6 +144,7 @@ const SelectField = React.createClass({
errorText,
onFocus,
onBlur,
labelMember,
...other,
} = this.props;

Expand All @@ -164,6 +167,7 @@ const SelectField = React.createClass({
iconStyle: this.mergeAndPrefix(styles.icon, iconStyle),
underlineStyle: this.mergeAndPrefix(styles.underline, underlineStyle),
autoWidth: false,
labelMember: labelMember,
};

return (
Expand Down