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

[ToggleButtonGroup] Consider nullish instead of falsy value as no selected value #13494

Merged
merged 1 commit into from
Dec 2, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ ToggleButtonGroup.propTypes = {
ToggleButtonGroup.defaultProps = {
exclusive: false,
selected: 'auto',
value: null,
};

export default withStyles(styles, { name: 'MuiToggleButtonGroup' })(ToggleButtonGroup);
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('<ToggleButtonGroup />', () => {

it('should not render a selected div when selected is "auto" and a value is missing', () => {
const wrapper = shallow(
<ToggleButtonGroup selected="auto" value={null}>
<ToggleButtonGroup selected="auto">
<ToggleButton value="hello" />
</ToggleButtonGroup>,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/ToggleButtonGroup/hasValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default function hasValue(value) {
return value.length > 0;
}

return !!value;
return value != null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ describe('<ToggleButton /> hasValue', () => {
it('should be false for null', () => {
assert.strictEqual(hasValue(null), false);
});

it('should be true for empty string', () => {
assert.strictEqual(hasValue(''), true);
});
});
2 changes: 1 addition & 1 deletion pages/lab/api/toggle-button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
| <span class="prop-name">exclusive</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, only allow one of the child ToggleButton values to be selected. |
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> |   | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: object) => void`<br>*event:* The event source of the callback<br>*value:* of the selected buttons. When `exclusive` is true this is a single value; when false an array of selected values. If no value is selected the value is null. |
| <span class="prop-name">selected</span> | <span class="prop-type">union:&nbsp;bool&nbsp;&#124;<br>&nbsp;enum:&nbsp;'auto'<br><br></span> | <span class="prop-default">'auto'</span> | If `true`, render the group in a selected state. If `auto` (the default) render in a selected state if `value` is not empty. |
| <span class="prop-name">value</span> | <span class="prop-type">any</span> | <span class="prop-default">null</span> | The currently selected value within the group or an array of selected values when `exclusive` is false. |
| <span class="prop-name">value</span> | <span class="prop-type">any</span> |   | The currently selected value within the group or an array of selected values when `exclusive` is false. |

Any other properties supplied will be spread to the root element (native element).

Expand Down