Skip to content

Commit

Permalink
[Snackbar] Fix prop type error for 'key' prop (mui#25431)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Tassinari <[email protected]>
  • Loading branch information
jansedlon and oliviertassinari authored Mar 22, 2021
1 parent c434fe1 commit 5c7d54b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/snackbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ClickAwayListenerProps": { "type": { "name": "object" } },
"ContentProps": { "type": { "name": "object" } },
"disableWindowBlurListener": { "type": { "name": "bool" } },
"key": { "type": { "name": "any" } },
"key": { "type": { "name": "custom", "description": "any" } },
"message": { "type": { "name": "node" } },
"onClose": { "type": { "name": "func" } },
"open": { "type": { "name": "bool" } },
Expand Down
3 changes: 3 additions & 0 deletions docs/src/modules/utils/generatePropTypeDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default function generatePropTypeDescription(type: PropTypeDescriptor): s
if (type.raw === 'HTMLElementType') {
return 'HTML element';
}
if (type.raw === '() => null') {
return 'any';
}

const deprecatedInfo = getDeprecatedInfo(type);
if (deprecatedInfo !== false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Snackbar.propTypes /* remove-proptypes */ = {
* e.g. <Snackbar key={message} />, otherwise, the message may update-in-place and
* features such as autoHideDuration may be canceled.
*/
key: PropTypes.any,
key: () => null,
/**
* The message to display.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/typescript-to-proptypes/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ export function generate(component: t.Component, options: GenerateOptions = {}):
}

if (propType.type === 'any') {
// key isn't a prop like the others, see
// https://github.com/mui-org/material-ui/issues/25304
if (context.propTypeDefinition.name === 'key') {
return '() => null';
}

return `${importedName}.any`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Snackbar.propTypes = {
/**
* some hints about state reset that relates to prop of this component
*/
key: PropTypes.any,
key: () => null,
};

export { Snackbar };
Expand Down

0 comments on commit 5c7d54b

Please sign in to comment.