Skip to content

Commit

Permalink
fix warning in the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 3, 2019
1 parent aaa98c3 commit cd7f4b9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">open</span> | <span class="prop-type">bool</span> | | Control `select` open state. You can only use it when the `native` prop is `false` (default). |
| <span class="prop-name">renderValue</span> | <span class="prop-type">func</span> | | Render the selected value. You can only use it when the `native` prop is `false` (default).<br><br>**Signature:**<br>`function(value: any) => ReactElement`<br>*value:* The `value` provided to the component. |
| <span class="prop-name">SelectDisplayProps</span> | <span class="prop-type">object</span> | | Props applied to the clickable div element. |
| <span class="prop-name">value</span> | <span class="prop-type">any</span> | | The input value. Providing an empty string will select no options. This prop is required when the `native` prop is `false` (default). |
| <span class="prop-name">value</span> | <span class="prop-type">any</span> | | The input value. Providing an empty string will select no options. This prop is required when the `native` prop is `false` (default). Set to an empty string `''` if you don't want any of the available options to be selected. |
| <span class="prop-name">variant</span> | <span class="prop-type">'standard'<br>&#124;&nbsp;'outlined'<br>&#124;&nbsp;'filled'</span> | <span class="prop-default">'standard'</span> | The variant to use. |

The `ref` is forwarded to the root element.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/selects/DialogSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function DialogSelect() {
});

const handleChange = name => event => {
setState({ ...state, [name]: event.target.value });
setState({ ...state, [name]: Number(event.target.value) || '' });
};

const handleClickOpen = () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/selects/DialogSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function DialogSelect() {
const handleChange = (name: keyof typeof state) => (
event: React.ChangeEvent<{ value: unknown }>,
) => {
setState({ ...state, [name]: Number(event.target.value) });
setState({ ...state, [name]: Number(event.target.value) || '' });
};

const handleClickOpen = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/material-ui/src/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Select.propTypes = {
/**
* The input value. Providing an empty string will select no options.
* This prop is required when the `native` prop is `false` (default).
* Set to an empty string `''` if you don't want any of the available options to be selected.
*/
value: PropTypes.any,
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe('<Select />', () => {
);
expect(console.warn.callCount).to.equal(1);
expect(console.warn.args[0][0]).to.include(
'Material-UI: you have provided an out-of-range value for the select component.',
'Material-UI: you have provided an out-of-range value `20` for the select component.',
);
});
});
Expand Down
8 changes: 3 additions & 5 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,13 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useEffect(() => {
if (!foundMatch && !multiple && value !== '') {
const values = React.Children.toArray(children)
.map(child => child.props.value)
.filter(val => val !== '');
const values = React.Children.toArray(children).map(child => child.props.value);
console.warn(
[
`Material-UI: you have provided an out-of-range value for the select ${
`Material-UI: you have provided an out-of-range value \`${value}\` for the select ${
name ? `(name="${name}") ` : ''
}component.`,
'Consider providing a value that matches one of the available options.',
"Consider providing a value that matches one of the available options or ''.",
`The available values are ${values.join(', ') || '""'}.`,
].join('\n'),
);
Expand Down
34 changes: 17 additions & 17 deletions packages/material-ui/src/TablePagination/TablePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('<TablePagination />', () => {

before(() => {
classes = getClasses(
<TablePagination count={1} onChangePage={() => {}} page={0} rowsPerPage={1} />,
<TablePagination count={1} onChangePage={() => {}} page={0} rowsPerPage={10} />,
);
// StrictModeViolation: uses #html()
mount = createMount({ strict: false });
Expand All @@ -41,7 +41,7 @@ describe('<TablePagination />', () => {
});

describeConformance(
<TablePagination count={1} onChangePage={() => {}} page={0} rowsPerPage={1} />,
<TablePagination count={1} onChangePage={() => {}} page={0} rowsPerPage={10} />,
() => ({
classes,
inheritComponent: TableCell,
Expand All @@ -57,8 +57,8 @@ describe('<TablePagination />', () => {
let labelDisplayedRowsCalled = false;
function labelDisplayedRows({ from, to, count, page }) {
labelDisplayedRowsCalled = true;
assert.strictEqual(from, 6);
assert.strictEqual(to, 10);
assert.strictEqual(from, 11);
assert.strictEqual(to, 20);
assert.strictEqual(count, 42);
assert.strictEqual(page, 1);
return `Page ${page}`;
Expand All @@ -73,7 +73,7 @@ describe('<TablePagination />', () => {
page={1}
onChangePage={noop}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
labelDisplayedRows={labelDisplayedRows}
/>
</TableRow>
Expand All @@ -94,7 +94,7 @@ describe('<TablePagination />', () => {
page={0}
onChangePage={noop}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
labelRowsPerPage="Zeilen pro Seite:"
/>
</TableRow>
Expand All @@ -110,11 +110,11 @@ describe('<TablePagination />', () => {
<TableFooter>
<TableRow>
<TablePagination
count={6}
count={11}
page={0}
onChangePage={noop}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
/>
</TableRow>
</TableFooter>
Expand All @@ -133,11 +133,11 @@ describe('<TablePagination />', () => {
<TableFooter>
<TableRow>
<TablePagination
count={6}
count={11}
page={1}
onChangePage={noop}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
/>
</TableRow>
</TableFooter>
Expand All @@ -157,13 +157,13 @@ describe('<TablePagination />', () => {
<TableFooter>
<TableRow>
<TablePagination
count={15}
count={30}
page={page}
onChangePage={(event, nextPage) => {
page = nextPage;
}}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
/>
</TableRow>
</TableFooter>
Expand All @@ -182,13 +182,13 @@ describe('<TablePagination />', () => {
<TableFooter>
<TableRow>
<TablePagination
count={15}
count={30}
page={page}
onChangePage={(event, nextPage) => {
page = nextPage;
}}
onChangeRowsPerPage={noop}
rowsPerPage={5}
rowsPerPage={10}
/>
</TableRow>
</TableFooter>
Expand All @@ -208,7 +208,7 @@ describe('<TablePagination />', () => {
<TablePagination
count={0}
page={0}
rowsPerPage={5}
rowsPerPage={10}
onChangePage={noop}
onChangeRowsPerPage={noop}
/>
Expand Down Expand Up @@ -266,8 +266,8 @@ describe('<TablePagination />', () => {
<TableRow>
<TablePagination
page={2}
rowsPerPage={5}
count={10}
count={20}
rowsPerPage={10}
onChangePage={noop}
onChangeRowsPerPage={noop}
/>
Expand Down
6 changes: 6 additions & 0 deletions test/utils/consoleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ function consoleError() {
console.info(...args);
throw new Error(...args);
};

console.warn = (...args) => {
// Can't use log as karma is not displaying them.
console.info(...args);
throw new Error(...args);
};
}

module.exports = consoleError;

0 comments on commit cd7f4b9

Please sign in to comment.