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

Added Disabled Prop and Styles to DropDownMenu #1406

Merged
merged 3 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions docs/src/app/components/pages/components/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class DropDownMenuPage extends React.Component {
type: 'object',
header: 'optional',
desc: 'Overrides the inline-styles of DropDownMenu\'s root element.'
},
{
name: 'disabled',
type: 'bool',
header: 'default: false',
desc: 'Disables the menu.'
}
]
},
Expand Down
10 changes: 7 additions & 3 deletions src/drop-down-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let DropDownMenu = React.createClass({
displayMember: React.PropTypes.string,
valueMember: React.PropTypes.string,
autoWidth: React.PropTypes.bool,
disabled: React.PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

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

can you add the default value false in getDefaultProps so that it's straightforward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks

onChange: React.PropTypes.func,
menuItems: React.PropTypes.array.isRequired,
menuItemStyle: React.PropTypes.object,
Expand Down Expand Up @@ -65,6 +66,7 @@ let DropDownMenu = React.createClass({

getStyles(){
let zIndex = 5; // As AppBar
let disabled = this.props.disabled;
Copy link
Member

Choose a reason for hiding this comment

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

const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand what const is, but not the purpose of your line note. Const is not used anywhere else in this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mjhasbach Understood. We're trying to update our files with const where appropriate and it looks like you happened to find a file we haven't touched yet. When accessing this.props you should always write

// this.props is immutable within the context of this so we should treat it as such
const { style, children } = this.props; 

if you are going to expand this.props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make sure we're on the same page...

The purpose of disabled is to make property value ternary evaluations of the object literal styles more terse. Because this.props.disabled is a React.PropTypes.bool, mutating disabled would not mutate this.props.disabled.

Therefore, are you saying that disabled should be declared with const instead of let to make it clear that disabled should not be mutated (even though doing so would not mutate this.props)?

Copy link
Member

Choose a reason for hiding this comment

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

More or less. It should be declared const because disabled is not and should probably not be mutated (yes because he come from a prop which is a source of truth).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. I made the requested change.

let spacing = this.context.muiTheme.spacing;
let accentColor = this.context.muiTheme.component.dropDownMenu.accentColor;
let backgroundColor = this.context.muiTheme.component.menu.backgroundColor;
Expand All @@ -78,7 +80,7 @@ let DropDownMenu = React.createClass({
outline: 'none',
},
control: {
cursor: 'pointer',
cursor: disabled ? 'not-allowed' : 'pointer',
position: 'static',
height: '100%',
},
Expand All @@ -102,7 +104,7 @@ let DropDownMenu = React.createClass({
paddingLeft: spacing.desktopGutter,
top: 0,
opacity: 1,
color: this.context.muiTheme.palette.textColor,
color: disabled ? this.context.muiTheme.palette.disabledColor : this.context.muiTheme.palette.textColor,
},
underline: {
borderTop: 'solid 1px ' + accentColor,
Expand Down Expand Up @@ -240,7 +242,9 @@ let DropDownMenu = React.createClass({
},

_onControlClick() {
this.setState({ open: !this.state.open });
if (!this.props.disabled) {
this.setState({ open: !this.state.open });
}
},

_onKeyDown(e) {
Expand Down