Skip to content

Commit

Permalink
[Form components] Set cursor:not-allowed style when disabled
Browse files Browse the repository at this point in the history
Affects the following components: Checkbox, DatePicker, EnhancedTextarea, IconButton, ListItem, MenuItem, RadioButton, SelectField, Stepper, Table, TextField, Toggle
  • Loading branch information
Nikita Shulipa committed Jun 14, 2016
1 parent 81d74af commit 065ca12
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ function getStyles(props, context) {
},
checkWhenDisabled: {
fill: checkbox.disabledColor,
cursor: 'not-allowed',
},
boxWhenDisabled: {
fill: props.checked ? 'transparent' : checkbox.disabledColor,
cursor: 'not-allowed',
},
label: {
color: props.disabled ? checkbox.labelDisabledColor : checkbox.labelColor,
Expand Down
2 changes: 1 addition & 1 deletion src/DatePicker/DateDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getStyles(props, context, state) {
marginBottom: 10,
},
yearTitle: {
cursor: (!selectedYear && !props.disableYearSelection) ? 'pointer' : 'default',
cursor: props.disableYearSelection ? 'not-allowed' : (!selectedYear ? 'pointer' : 'default'),
},
};

Expand Down
1 change: 1 addition & 0 deletions src/IconButton/IconButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function getStyles(props, context) {
disabled: {
color: baseTheme.palette.disabledColor,
fill: baseTheme.palette.disabledColor,
cursor: 'not-allowed',
},
};
}
Expand Down
1 change: 1 addition & 0 deletions src/MenuItem/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function getStyles(props, context) {
const styles = {
root: {
color: props.disabled ? disabledColor : textColor,
cursor: props.disabled ? 'not-allowed' : 'inherit',
lineHeight: props.desktop ? '32px' : '48px',
fontSize: props.desktop ? 15 : 16,
whiteSpace: 'nowrap',
Expand Down
2 changes: 2 additions & 0 deletions src/RadioButton/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ function getStyles(props, context) {
},
targetWhenDisabled: {
fill: radioButton.disabledColor,
cursor: 'not-allowed',
},
fillWhenDisabled: {
fill: radioButton.disabledColor,
cursor: 'not-allowed',
},
label: {
color: props.disabled ? radioButton.labelDisabledColor : radioButton.labelColor,
Expand Down
1 change: 1 addition & 0 deletions src/SelectField/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class SelectField extends Component {
<TextField
{...other}
style={style}
disabled={disabled}
floatingLabelFixed={floatingLabelFixed}
floatingLabelText={floatingLabelText}
floatingLabelStyle={floatingLabelStyle}
Expand Down
1 change: 1 addition & 0 deletions src/Stepper/StepLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const getStyles = ({active, completed, disabled}, {muiTheme, stepper}) => {
if (disabled) {
styles.icon.color = inactiveIconColor;
styles.root.color = disabledTextColor;
styles.root.cursor = 'not-allowed';
}

return styles;
Expand Down
8 changes: 6 additions & 2 deletions src/Table/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ class TableBody extends Component {
if (!this.props.displayRowCheckbox) return null;

const key = `${rowProps.rowNumber}-cb`;
const disabled = !this.props.selectable;
const checkbox = (
<Checkbox
ref="rowSelectCB"
name={key}
value="selected"
disabled={!this.props.selectable}
disabled={disabled}
checked={rowProps.selected}
/>
);
Expand All @@ -204,7 +205,10 @@ class TableBody extends Component {
<TableRowColumn
key={key}
columnNumber={0}
style={{width: 24}}
style={{
width: 24,
cursor: disabled ? 'not-allowed' : 'inherit',
}}
>
{checkbox}
</TableRowColumn>
Expand Down
22 changes: 19 additions & 3 deletions src/Table/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,43 @@ class TableHeader extends Component {
getCheckboxPlaceholder(props) {
if (!this.props.adjustForCheckbox) return null;

const disabled = !this.props.enableSelectAll;
const key = `hpcb${props.rowNumber}`;
return <TableHeaderColumn key={key} style={{width: 24}} />;
return (
<TableHeaderColumn
key={key}
style={{
width: 24,
cursor: disabled ? 'not-allowed' : 'inherit',
}}
/>
);
}

getSelectAllCheckboxColumn(props) {
if (!this.props.displaySelectAll) return this.getCheckboxPlaceholder(props);

const disabled = !this.props.enableSelectAll;
const checkbox = (
<Checkbox
key="selectallcb"
name="selectallcb"
value="selected"
disabled={!this.props.enableSelectAll}
disabled={disabled}
checked={this.props.selectAllSelected}
onCheck={this.handleCheckAll}
/>
);

const key = `hpcb${props.rowNumber}`;
return (
<TableHeaderColumn key={key} style={{width: 24}}>
<TableHeaderColumn
key={key}
style={{
width: 24,
cursor: disabled ? 'not-allowed' : 'inherit',
}}
>
{checkbox}
</TableHeaderColumn>
);
Expand Down
2 changes: 1 addition & 1 deletion src/TextField/EnhancedTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getStyles(props, context, state) {
resize: 'none',
font: 'inherit',
padding: 0,
cursor: props.disabled ? 'default' : 'initial',
cursor: props.disabled ? 'not-allowed' : 'initial',
},
shadow: {
resize: 'none',
Expand Down
1 change: 1 addition & 0 deletions src/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const getStyles = (props, context, state) => {
outline: 'none',
backgroundColor: 'rgba(0,0,0,0)',
color: props.disabled ? disabledTextColor : textColor,
cursor: props.disabled ? 'not-allowed' : 'initial',
font: 'inherit',
},
textarea: {},
Expand Down
2 changes: 1 addition & 1 deletion src/TextField/TextFieldLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function getStyles(props) {
top: 38,
transition: transitions.easeOut(),
zIndex: 1, // Needed to display label above Chrome's autocomplete field background
cursor: props.disabled ? 'default' : 'text',
cursor: props.disabled ? 'not-allowed' : 'text',
transform: 'scale(1) translate3d(0, 0, 0)',
transformOrigin: 'left top',
pointerEvents: 'auto',
Expand Down
1 change: 1 addition & 0 deletions src/TextField/TextFieldUnderline.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const TextFieldUnderline = (props) => {
disabled: {
borderBottom: 'dotted 2px',
borderColor: disabledTextColor,
cursor: 'not-allowed',
},
focus: {
borderBottom: 'solid 2px',
Expand Down
3 changes: 3 additions & 0 deletions src/Toggle/Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ function getStyles(props, context, state) {
},
trackWhenDisabled: {
backgroundColor: toggle.trackDisabledColor,
cursor: 'not-allowed',
},
thumbWhenDisabled: {
backgroundColor: toggle.thumbDisabledColor,
cursor: 'not-allowed',
},
label: {
color: disabled ? toggle.labelDisabledColor : toggle.labelColor,
width: `calc(100% - ${(toggleTrackWidth + 10)}px)`,
cursor: disabled ? 'not-allowed' : 'initial',
},
};

Expand Down

0 comments on commit 065ca12

Please sign in to comment.