1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Fix aria label error on the console (#18370)

* fix aria label bug

* improve solution

* improve solution

* improve solution

* update snapshot
This commit is contained in:
Pedro Figueiredo 2023-03-30 18:33:42 +01:00 committed by GitHub
parent da06901f79
commit 05f0006684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -296,7 +296,7 @@ exports[`Account Menu Render Content should not render keyring label if keyring
class="account-menu__item__icon"
>
<span
arialabel="Settings"
aria-label="Settings"
class="box mm-icon mm-icon--size-md box--display-inline-block box--flex-direction-row box--color-icon-alternative"
style="mask-image: url('./images/icons/setting.svg');"
/>

View File

@ -222,6 +222,7 @@ const Box = React.forwardRef(function Box(
className,
backgroundColor,
color,
ariaLabel,
as = 'div',
...props
},
@ -300,13 +301,31 @@ const Box = React.forwardRef(function Box(
return children(boxClassName);
}
const Component = as;
const ariaLabelProp = {};
if (isCustomComponent(Component)) {
ariaLabelProp.ariaLabel = ariaLabel;
} else {
ariaLabelProp['aria-label'] = ariaLabel;
}
if (props['aria-label']) {
ariaLabelProp['aria-label'] = props['aria-label'];
}
return (
<Component className={boxClassName} ref={ref} {...props}>
<Component className={boxClassName} ref={ref} {...props} {...ariaLabelProp}>
{children}
</Component>
);
});
// Both class or functional components have type function.
// Built-in HTML elements (div, span, etc.) have type string.
function isCustomComponent(element) {
return typeof element.type === 'function';
}
Box.propTypes = {
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
flexDirection: PropTypes.oneOfType([
@ -372,6 +391,8 @@ Box.propTypes = {
* ./ui/helpers/constants/design-system.js
*/
color: MultipleTextColors,
ariaLabel: PropTypes.string,
'aria-label': PropTypes.string,
};
export default Box;