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

[ToggleButton] Change ToggleButtonGroup non-exclusive default value to an empty array #13857

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 @@ -34,7 +34,6 @@ class ToggleButtonGroup extends React.Component {
if (value && index >= 0) {
newValue = [...value];
newValue.splice(index, 1);
if (newValue.length === 0) newValue = null;
} else {
newValue = value ? [...value, buttonValue] : [buttonValue];
}
Expand Down Expand Up @@ -120,7 +119,7 @@ ToggleButtonGroup.propTypes = {
* @param {object} event The event source of the callback
* @param {object} 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.
* is selected and `exclusive` is true the value is null; when false an empty array.
*/
onChange: PropTypes.func,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('<ToggleButtonGroup />', () => {
});

describe('non exclusive', () => {
it('should be null when current value is toggled off', () => {
it('should be an empty array when current value is toggled off', () => {
const handleChange = spy();
const wrapper = mount(
<ToggleButtonGroup value={['one']} onChange={handleChange}>
Expand All @@ -193,7 +193,8 @@ describe('<ToggleButtonGroup />', () => {
.simulate('click');

assert.strictEqual(handleChange.callCount, 1);
assert.strictEqual(handleChange.args[0][1], null);
assert.ok(Array.isArray(handleChange.args[0][1]));
assert.strictEqual(handleChange.args[0][1].length, 0);
});

it('should be an array with a single value when value is toggled on', () => {
Expand Down
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 @@ -21,7 +21,7 @@ import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
| <span class="prop-name required">children *</span> | <span class="prop-type">node</span> |   | The content of the button. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> |   | Useful to extend the style applied to components. |
| <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">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 and `exclusive` is true the value is null; when false an empty array. |
| <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> |   | The currently selected value within the group or an array of selected values when `exclusive` is false. |

Expand Down