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 @@ -121,6 +121,10 @@ class DropDownMenu extends Component {
* The maximum height of the `Menu` when it is displayed.
*/
maxHeight: PropTypes.number,
/**
* Override the inline-styles of menu items.
*/
menuItemStyle: PropTypes.object,
/**
* Overrides the styles of `Menu` when the `DropDownMenu` is displayed.
*/
Expand All @@ -141,6 +145,10 @@ class DropDownMenu extends Component {
* Set to true to have the `DropDownMenu` automatically open on mount.
*/
openImmediately: PropTypes.bool,
/**
* Override the inline-styles of selected menu items.
*/
selectedMenuItemStyle: PropTypes.object,
/**
* Override the inline-styles of the root element.
*/
Expand Down Expand Up @@ -268,6 +276,8 @@ class DropDownMenu extends Component {
menuStyle: menuStyleProp,
onClose, // eslint-disable-line no-unused-vars
openImmediately, // eslint-disable-line no-unused-vars
menuItemStyle,
selectedMenuItemStyle,
style,
underlineStyle,
value,
Expand Down Expand Up @@ -330,6 +340,8 @@ class DropDownMenu extends Component {
style={menuStyle}
listStyle={listStyle}
onItemTouchTap={this.handleItemTouchTap}
menuItemStyle={menuItemStyle}
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 @@ -60,4 +60,36 @@ describe('<DropDownMenu />', () => {
}, 0);
});
});

it('passes expected props through to the underlying Menu', () => {
const props = {
listStyle: {color: 'black'},
maxHeight: 10,
menuStyle: {color: 'white'},
menuItemStyle: {fontWeight: 'bold'},
selectedMenuItemStyle: {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,
selectedMenuItemStyle: props.selectedMenuItemStyle,
style: props.menuStyle,
value: props.value,
});
});
});
10 changes: 8 additions & 2 deletions src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class Menu extends Component {
* height.
*/
maxHeight: PropTypes.number,
/**
* 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,7 +115,7 @@ class Menu extends Component {
onItemTouchTap: PropTypes.func,
/** @ignore */
onKeyDown: PropTypes.func,
Copy link
Member

Choose a reason for hiding this comment

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

I would rather keep that name to not introduce breaking changes.

/**
/**
Copy link
Member

Choose a reason for hiding this comment

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

space typo

* Override the inline-styles of selected menu items.
*/
selectedMenuItemStyle: PropTypes.object,
Expand Down Expand Up @@ -233,6 +237,7 @@ class Menu extends Component {
cloneMenuItem(child, childIndex, styles, index) {
const {
desktop,
menuItemStyle,
selectedMenuItemStyle,
} = this.props;

Expand All @@ -243,7 +248,7 @@ class Menu extends Component {
selectedChildrenStyles = Object.assign(styles.selectedMenuItem, selectedMenuItemStyle);
}

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 @@ -475,6 +480,7 @@ class Menu extends Component {
onItemTouchTap, // eslint-disable-line no-unused-vars
onEscKeyDown, // eslint-disable-line no-unused-vars
selectedMenuItemStyle, // 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 @@ -91,6 +91,10 @@ class SelectField extends Component {
* Override the default max-height of the underlying `DropDownMenu` element.
*/
maxHeight: PropTypes.number,
/**
* Override the inline-styles of menu items.
*/
menuItemStyle: PropTypes.object,
/**
* Override the inline-styles of the underlying `DropDownMenu` element.
*/
Expand All @@ -108,6 +112,10 @@ class SelectField extends Component {
onChange: PropTypes.func,
/** @ignore */
onFocus: 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 @@ -152,6 +160,8 @@ class SelectField extends Component {
id,
underlineDisabledStyle,
underlineFocusStyle,
menuItemStyle,
selectedMenuItemStyle,
underlineStyle,
errorStyle,
disabled,
Expand Down Expand Up @@ -199,6 +209,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}
selectedMenuItemStyle={selectedMenuItemStyle}
underlineStyle={styles.hideDropDownUnderline}
listStyle={listStyle}
autoWidth={autoWidth}
Expand Down
22 changes: 20 additions & 2 deletions src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ function getStyles(props, context, state) {

const {open} = state;

const {position} = props;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like change on the Snackbar wasn't intended to be in that PR.

Copy link
Author

@DoubleU23 DoubleU23 Dec 16, 2016

Choose a reason for hiding this comment

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

oh no, sry.
that were the changes of #5437
because i already merged it into master in my branch...
=> set it to actual content of Snackbar.js

const positionProperties = {};
let transitionOperator = '';
if (position === 'top') {
positionProperties.top = 0;
transitionOperator = '-';
} else {
positionProperties.bottom = 0;
}

const styles = {
root: {
position: 'fixed',
...positionProperties,
left: '50%',
display: 'flex',
bottom: 0,
zIndex: zIndex.snackbar,
visibility: open ? 'visible' : 'hidden',
transform: open ?
'translate(-50%, 0)' :
`translate(-50%, ${desktopSubheaderHeight}px)`,
`translate(-50%, ${transitionOperator}${desktopSubheaderHeight}px)`,
transition: `${transitions.easeOut('400ms', 'transform')}, ${
transitions.easeOut('400ms', 'visibility')}`,
},
Expand Down Expand Up @@ -92,12 +102,20 @@ class Snackbar extends Component {
* Controls whether the `Snackbar` is opened or not.
*/
open: PropTypes.bool.isRequired,
/**
* Defines if the Snackbar is positioned on bottom or on top of the page
*/
position: PropTypes.oneOf(['top', 'bottom']),
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
};

static defaultProps = {
position: 'top',
};

static contextTypes = {
muiTheme: PropTypes.object.isRequired,
};
Expand Down