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

[Menu][DropDownMenu][SelectField] Add menuItemStyle and menuItemSelectedStyle properties #5389

Merged
merged 10 commits into from
Dec 16, 2016
12 changes: 12 additions & 0 deletions src/DropDownMenu/DropDownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ class DropDownMenu extends Component {
* The maximum height of the `Menu` when it is displayed.
*/
maxHeight: PropTypes.number,
/**
* Override the inline-styles of selected menu items.
*/
menuItemSelectedStyle: PropTypes.object,
/**
* Override the inline-styles of menu items.
*/
menuItemStyle: PropTypes.object,
/**
* Overrides the styles of `Menu` when the `DropDownMenu` is displayed.
*/
Expand Down Expand Up @@ -253,6 +261,8 @@ class DropDownMenu extends Component {
maxHeight,
menuStyle: menuStyleProp,
openImmediately, // eslint-disable-line no-unused-vars
menuItemStyle,
menuItemSelectedStyle,
style,
underlineStyle,
value,
Expand Down Expand Up @@ -315,6 +325,8 @@ class DropDownMenu extends Component {
style={menuStyle}
listStyle={listStyle}
onItemTouchTap={this.handleItemTouchTap}
menuItemStyle={menuItemStyle}
menuItemSelectedStyle={menuItemSelectedStyle}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about?

selectedMenuItemStyle={selectedMenuItemStyle}

>
{children}
</Menu>
Expand Down
32 changes: 32 additions & 0 deletions src/DropDownMenu/DropDownMenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,36 @@ describe('<DropDownMenu />', () => {

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

it('passes expected props through to the underlying Menu', () => {
const props = {
listStyle: {color: 'black'},
maxHeight: 10,
menuStyle: {color: 'white'},
menuItemStyle: {fontWeight: 'bold'},
menuItemSelectedStyle: {color: 'blue'},
value: 1,
};

const wrapper = shallowWithContext(
<DropDownMenu
{...props}
>
<div value={1} primaryText="Never" />
<div value={2} primaryText="Every Night" />
<div value={3} primaryText="Weeknights" />
</DropDownMenu>
);

const menu = wrapper.childAt(1).childAt(0);
assert.include(menu.props(), {
desktop: true,
listStyle: props.listStyle,
maxHeight: props.maxHeight,
menuItemStyle: props.menuItemStyle,
menuItemSelectedStyle: props.menuItemSelectedStyle,
style: props.menuStyle,
value: props.value,
});
});
});
22 changes: 14 additions & 8 deletions src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class Menu extends Component {
* height.
*/
maxHeight: PropTypes.number,
/**
* Override the inline-styles of selected menu items.
*/
menuItemSelectedStyle: PropTypes.object,
/**
* Override the inline-styles of menu items.
*/
menuItemStyle: PropTypes.object,
/**
* If true, `value` must be an array and the menu will support
* multiple selections.
Expand Down Expand Up @@ -111,10 +119,6 @@ class Menu extends Component {
onItemTouchTap: PropTypes.func,
/** @ignore */
onKeyDown: PropTypes.func,
/**
* Override the inline-styles of selected menu items.
*/
selectedMenuItemStyle: PropTypes.object,
/**
* Override the inline-styles of the root element.
*/
Expand Down Expand Up @@ -233,17 +237,18 @@ class Menu extends Component {
cloneMenuItem(child, childIndex, styles, index) {
const {
desktop,
selectedMenuItemStyle,
menuItemStyle,
menuItemSelectedStyle,
} = this.props;

const selected = this.isChildSelected(child, this.props);
let selectedChildrenStyles = {};

if (selected) {
selectedChildrenStyles = Object.assign(styles.selectedMenuItem, selectedMenuItemStyle);
selectedChildrenStyles = Object.assign(styles.selectedMenuItem, menuItemSelectedStyle);
}

const mergedChildrenStyles = Object.assign({}, child.props.style, selectedChildrenStyles);
const mergedChildrenStyles = Object.assign({}, child.props.style, menuItemStyle, selectedChildrenStyles);

const isFocused = childIndex === this.state.focusIndex;
let focusState = 'none';
Expand Down Expand Up @@ -450,7 +455,8 @@ class Menu extends Component {
multiple, // eslint-disable-line no-unused-vars
onItemTouchTap, // eslint-disable-line no-unused-vars
onEscKeyDown, // eslint-disable-line no-unused-vars
selectedMenuItemStyle, // eslint-disable-line no-unused-vars
menuItemSelectedStyle, // eslint-disable-line no-unused-vars
menuItemStyle, // eslint-disable-line no-unused-vars
style,
value, // eslint-disable-line no-unused-vars
valueLink, // eslint-disable-line no-unused-vars
Expand Down
12 changes: 12 additions & 0 deletions src/SelectField/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class SelectField extends Component {
* Override the default max-height of the underlying `DropDownMenu` element.
*/
maxHeight: PropTypes.number,
/**
* Override the inline-styles of selected menu items.
*/
menuItemSelectedStyle: PropTypes.object,
/**
* Override the inline-styles of menu items.
*/
menuItemStyle: PropTypes.object,
/**
* Override the inline-styles of the underlying `DropDownMenu` element.
*/
Expand Down Expand Up @@ -148,6 +156,8 @@ class SelectField extends Component {
id,
underlineDisabledStyle,
underlineFocusStyle,
menuItemStyle,
menuItemSelectedStyle,
underlineStyle,
errorStyle,
disabled,
Expand Down Expand Up @@ -194,6 +204,8 @@ class SelectField extends Component {
style={Object.assign(styles.dropDownMenu, menuStyle)}
labelStyle={Object.assign(styles.label, labelStyle)}
iconStyle={Object.assign(styles.icon, iconStyle)}
menuItemStyle={menuItemStyle}
menuItemSelectedStyle={menuItemSelectedStyle}
underlineStyle={styles.hideDropDownUnderline}
autoWidth={autoWidth}
value={value}
Expand Down