Skip to content

Commit

Permalink
Merge branch 'master' into autocomplete_bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Mar 15, 2020
2 parents 926f428 + 383175a commit 60cc525
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 174 deletions.
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ trigger:
- l10n
- dependabot/*

# https://developercommunity.visualstudio.com/comments/949241/view.html
pr:
branches:
include:
- '*'

pool:
vmImage: 'ubuntu-latest'

Expand Down
5 changes: 5 additions & 0 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const workspaceRoot = path.join(__dirname, '../');
const reactMode = 'legacy';

module.exports = {
typescript: {
// Motivated by https://github.com/zeit/next.js/issues/7687
ignoreDevErrors: true,
ignoreBuildErrors: true,
},
webpack: (config, options) => {
const plugins = config.plugins.concat([
new webpack.DefinePlugin({
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"cross-fetch": "^3.0.4",
"css-loader": "^3.1.0",
"css-mediaquery": "^0.1.2",
"date-fns": "2.10.0",
"date-fns": "2.11.0",
"docsearch.js": "^2.6.3",
"doctrine": "^3.0.0",
"express": "^4.17.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api-docs/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">clearText</span> | <span class="prop-type">string</span> | <span class="prop-default">'Clear'</span> | Override the default text for the *clear* icon button.<br>For localization purposes, you can use the provided [translations](/guides/localization/). |
| <span class="prop-name">closeIcon</span> | <span class="prop-type">node</span> | <span class="prop-default">&lt;CloseIcon fontSize="small" /></span> | The icon to display in place of the default close icon. |
| <span class="prop-name">closeText</span> | <span class="prop-type">string</span> | <span class="prop-default">'Close'</span> | Override the default text for the *close popup* icon button.<br>For localization purposes, you can use the provided [translations](/guides/localization/). |
| <span class="prop-name">debug</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the popup will ignore the blur event if the input if filled. You can inspect the popup markup with your browser tools. Consider this option when you need to customize the component. |
| <span class="prop-name">debug</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the popup will ignore the blur event if the input is filled. You can inspect the popup markup with your browser tools. Consider this option when you need to customize the component. |
| <span class="prop-name">defaultValue</span> | <span class="prop-type">any<br>&#124;&nbsp;array</span> | <span class="prop-default">props.multiple ? [] : null</span> | The default input value. Use when the component is not controlled. |
| <span class="prop-name">disableClearable</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the input can't be cleared. |
| <span class="prop-name">disableCloseOnSelect</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the popup won't close when a value is selected. |
Expand Down
6 changes: 5 additions & 1 deletion docs/src/pages/components/autocomplete/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Each of the following examples demonstrate one feature of the Autocomplete compo

### Country select

Choose one country between 248.
Choose one of the 248 countries.

{{"demo": "pages/components/autocomplete/CountrySelect.js"}}

Expand Down Expand Up @@ -220,6 +220,10 @@ To fully take advantage of type inference, you need to set the `multiple` prop t
See [this discussion](https://github.com/mui-org/material-ui/pull/18854#discussion_r364215153) for more details.
TypeScript might solve this bug in the future.
### ListboxComponent
If you provide a custom `ListboxComponent` prop, you need to make sure that the intended scroll container has the `role` attribute set to `listbox`. This ensures the correct behavior of the scroll, for example when using the keyboard to navigate.
## Accessibility
(WAI-ARIA: https://www.w3.org/TR/wai-aria-practices/#combobox)
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/NativeSelects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ export default function NativeSelects() {
name: 'hai',
});

const inputLabel = React.useRef(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current.offsetWidth);
}, []);

const handleChange = name => event => {
setState({
...state,
Expand Down Expand Up @@ -200,14 +194,12 @@ export default function NativeSelects() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple">
Age
</InputLabel>
<InputLabel htmlFor="outlined-age-native-simple">Age</InputLabel>
<Select
native
value={state.age}
onChange={handleChange('age')}
labelWidth={labelWidth}
label="Age"
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/NativeSelects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ export default function NativeSelects() {
name: 'hai',
});

const inputLabel = React.useRef<HTMLLabelElement>(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current!.offsetWidth);
}, []);

const handleChange = (name: keyof typeof state) => (
event: React.ChangeEvent<{ value: unknown }>,
) => {
Expand Down Expand Up @@ -204,14 +198,12 @@ export default function NativeSelects() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple">
Age
</InputLabel>
<InputLabel htmlFor="outlined-age-native-simple">Age</InputLabel>
<Select
native
value={state.age}
onChange={handleChange('age')}
labelWidth={labelWidth}
label="Age"
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/SimpleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export default function SimpleSelect() {
const classes = useStyles();
const [age, setAge] = React.useState('');

const inputLabel = React.useRef(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current.offsetWidth);
}, []);

const handleChange = event => {
setAge(event.target.value);
};
Expand Down Expand Up @@ -195,15 +189,13 @@ export default function SimpleSelect() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} id="demo-simple-select-outlined-label">
Age
</InputLabel>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
labelWidth={labelWidth}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/SimpleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export default function SimpleSelect() {
const classes = useStyles();
const [age, setAge] = React.useState('');

const inputLabel = React.useRef<HTMLLabelElement>(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current!.offsetWidth);
}, []);

const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => {
setAge(event.target.value as string);
};
Expand Down Expand Up @@ -197,15 +191,13 @@ export default function SimpleSelect() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} id="demo-simple-select-outlined-label">
Age
</InputLabel>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
labelWidth={labelWidth}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@babel/preset-react": "^7.8.3",
"@babel/register": "^7.8.6",
"@rollup/plugin-replace": "^2.3.1",
"@testing-library/dom": "^6.8.1",
"@testing-library/dom": "^7.0.3",
"@testing-library/react": "^9.3.2",
"@testing-library/react-hooks": "3.2.1",
"@types/chai": "^4.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ Autocomplete.propTypes = {
*/
closeText: PropTypes.string,
/**
* If `true`, the popup will ignore the blur event if the input if filled.
* If `true`, the popup will ignore the blur event if the input is filled.
* You can inspect the popup markup with your browser tools.
* Consider this option when you need to customize the component.
*/
Expand Down
25 changes: 24 additions & 1 deletion packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,29 @@ describe('<Autocomplete />', () => {
});
});

describe('prop: clearOnEscape', () => {
it('should clear on escape', () => {
const handleChange = spy();
render(
<Autocomplete
{...defaultProps}
onChange={handleChange}
clearOnEscape
multiple
value={['one']}
options={['one', 'two']}
renderInput={params => <TextField {...params} autoFocus />}
/>,
);

fireEvent.keyDown(document.activeElement, { key: 'Escape' });
fireEvent.keyDown(document.activeElement, { key: 'Escape' });

expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.deep.equal([]);
});
});

describe('when popup open', () => {
it('closes the popup if Escape is pressed ', () => {
const handleClose = spy();
Expand Down Expand Up @@ -778,7 +801,7 @@ describe('<Autocomplete />', () => {
expect(handleChange.args[0][1]).to.equal('a');
expect(consoleErrorMock.callCount()).to.equal(2); // strict mode renders twice
expect(consoleErrorMock.messages()[0]).to.include(
'For the input option: "a", `getOptionLabel` returns: undefined',
'the `getOptionLabel` method of Autocomplete returned undefined instead of a string',
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface UseAutocompleteCommonProps<T> {
*/
componentName?: string;
/**
* If `true`, the popup will ignore the blur event if the input if filled.
* If `true`, the popup will ignore the blur event if the input is filled.
* You can inspect the popup markup with your browser tools.
* Consider this option when you need to customize the component.
*/
Expand Down
15 changes: 7 additions & 8 deletions packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ export default function useAutocomplete(props) {

if (process.env.NODE_ENV !== 'production') {
if (typeof optionLabel !== 'string') {
const erroneousReturn =
optionLabel === undefined ? 'undefined' : `${typeof optionLabel} (${optionLabel})`;
console.error(
[
'Material-UI: the `getOptionLabel` method of useAutocomplete do not handle the options correctly.',
`The component expect a string but received ${typeof optionLabel}.`,
`For the input option: ${JSON.stringify(
newValue,
)}, \`getOptionLabel\` returns: ${optionLabel}.`,
`Material-UI: the \`getOptionLabel\` method of ${componentName} returned ${erroneousReturn} instead of a string for`,
JSON.stringify(newValue),
].join('\n'),
);
}
Expand Down Expand Up @@ -465,7 +464,7 @@ export default function useAutocomplete(props) {
if (matches.length > 1) {
console.error(
[
'Material-UI: the `getOptionSelected` method of useAutocomplete do not handle the arguments correctly.',
`Material-UI: the \`getOptionSelected\` method of ${componentName} do not handle the arguments correctly.`,
`The component expects a single value to match a given option but found ${
matches.length
} matches.`,
Expand Down Expand Up @@ -649,7 +648,7 @@ export default function useAutocomplete(props) {
// Avoid the Modal to handle the event.
event.stopPropagation();
handleClose(event, 'escape');
} else if (clearOnEscape && inputValue !== '') {
} else if (clearOnEscape && (inputValue !== '' || (multiple && value.length > 0))) {
// Avoid Opera to exit fullscreen mode.
event.preventDefault();
// Avoid the Modal to handle the event.
Expand Down Expand Up @@ -976,7 +975,7 @@ useAutocomplete.propTypes = {
*/
componentName: PropTypes.string,
/**
* If `true`, the popup will ignore the blur event if the input if filled.
* If `true`, the popup will ignore the blur event if the input is filled.
* You can inspect the popup markup with your browser tools.
* Consider this option when you need to customize the component.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/material-ui/src/styles/createPalette.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ export interface TypeAction {
hover: string;
hoverOpacity: number;
selected: string;
selectedOpacity: number;
disabled: string;
disabledOpacity: number;
disabledBackground: string;
focus: string;
focusOpacity: number;
activatedOpacity: number;
}

export interface TypeBackground {
Expand Down
2 changes: 1 addition & 1 deletion scripts/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function runPrettier(changedFiles) {
console.log(
'\n\nThis project uses prettier to format all JavaScript code.\n' +
`Please run '${!changedFiles ? 'yarn prettier:all' : 'yarn prettier'}'` +
'and commit the changes to the files listed below:\n\n',
' and commit the changes to the files listed below:\n\n',
);
console.log(warnedFiles.join('\n'));
}
Expand Down
Loading

0 comments on commit 60cc525

Please sign in to comment.