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

refactor(Notification): ariaLabel to aria-label #13281

Merged
merged 6 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 11 additions & 4 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ Map {
"isRequired": true,
"type": "string",
},
"ariaLabel": Object {
"aria-label": Object {
"type": "string",
},
"ariaLabel": [Function],
"children": Object {
"type": "node",
},
Expand Down Expand Up @@ -4024,6 +4025,10 @@ Map {
"role": "status",
},
"propTypes": Object {
"aria-label": Object {
"type": "string",
},
"ariaLabel": [Function],
"children": Object {
"type": "node",
},
Expand Down Expand Up @@ -5061,7 +5066,7 @@ Map {
},
"NotificationButton" => Object {
"defaultProps": Object {
"ariaLabel": "close notification",
"aria-label": "close notification",
"notificationType": "toast",
"renderIcon": Object {
"$$typeof": Symbol(react.forward_ref),
Expand All @@ -5085,9 +5090,10 @@ Map {
"type": "button",
},
"propTypes": Object {
"ariaLabel": Object {
"aria-label": Object {
"type": "string",
},
"ariaLabel": [Function],
"className": Object {
"type": "string",
},
Expand Down Expand Up @@ -8441,9 +8447,10 @@ Map {
"timeout": 0,
},
"propTypes": Object {
"ariaLabel": Object {
"aria-label": Object {
"type": "string",
},
"ariaLabel": [Function],
"caption": Object {
"type": "string",
},
Expand Down
70 changes: 60 additions & 10 deletions packages/react/src/components/Notification/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import PropTypes from 'prop-types';
import React, { useEffect, useRef, useState } from 'react';
import deprecate from '../../prop-types/deprecate';
import cx from 'classnames';
import {
Close,
Expand Down Expand Up @@ -96,7 +97,8 @@ NotificationActionButton.propTypes = {
};

export function NotificationButton({
ariaLabel,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
className,
type,
renderIcon: IconTag,
Expand All @@ -119,8 +121,8 @@ export function NotificationButton({
{...rest}
// eslint-disable-next-line react/button-has-type
type={type}
aria-label={ariaLabel}
title={ariaLabel}
aria-label={deprecatedAriaLabel || ariaLabel}
title={deprecatedAriaLabel || ariaLabel}
className={buttonClassName}>
{IconTag && <IconTag className={iconClassName} name={name} />}
</button>
Expand All @@ -129,9 +131,18 @@ export function NotificationButton({

NotificationButton.propTypes = {
/**
* Specify a label to be read by screen readers on the notification button
* Specify a label to be read by screen readers on the container node
*/
ariaLabel: PropTypes.string,
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
* Specify a label to be read by screen readers on the container note.
*/
ariaLabel: deprecate(
PropTypes.string,
'This prop syntax has been deprecated. Please use the new `aria-label`.'
),

/**
* Specify an optional className to be applied to the notification button
Expand Down Expand Up @@ -162,7 +173,7 @@ NotificationButton.propTypes = {
};

NotificationButton.defaultProps = {
ariaLabel: 'close notification',
['aria-label']: 'close notification',
notificationType: 'toast',
type: 'button',
renderIcon: Close,
Expand Down Expand Up @@ -206,6 +217,8 @@ NotificationIcon.propTypes = {
};

export function ToastNotification({
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
role,
onClose,
onCloseButtonClick,
Expand Down Expand Up @@ -300,6 +313,7 @@ export function ToastNotification({
notificationType="toast"
onClick={handleCloseButtonClick}
aria-hidden="true"
aria-label={deprecatedAriaLabel || ariaLabel}
tabIndex="-1"
/>
)}
Expand All @@ -311,7 +325,16 @@ ToastNotification.propTypes = {
/**
* Provide a description for "close" icon button that can be read by screen readers
*/
ariaLabel: PropTypes.string,
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
* Provide a description for "close" icon button that can be read by screen readers
*/
ariaLabel: deprecate(
PropTypes.string,
'This prop syntax has been deprecated. Please use the new `aria-label`.'
),

/**
* Specify the caption
Expand Down Expand Up @@ -396,6 +419,8 @@ ToastNotification.defaultProps = {
};

export function InlineNotification({
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
francinelucca marked this conversation as resolved.
Show resolved Hide resolved
children,
title,
subtitle,
Expand Down Expand Up @@ -466,6 +491,7 @@ export function InlineNotification({
notificationType="inline"
onClick={handleCloseButtonClick}
aria-hidden="true"
aria-label={deprecatedAriaLabel || ariaLabel}
tabIndex="-1"
/>
)}
Expand All @@ -474,6 +500,20 @@ export function InlineNotification({
}

InlineNotification.propTypes = {
/**
* Provide a description for "close" icon button that can be read by screen readers
*/
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
* Provide a description for "close" icon button that can be read by screen readers
*/
ariaLabel: deprecate(
PropTypes.string,
'This prop syntax has been deprecated. Please use the new `aria-label`.'
),

/**
* Specify the content
*/
Expand Down Expand Up @@ -547,7 +587,8 @@ InlineNotification.defaultProps = {

export function ActionableNotification({
actionButtonLabel,
ariaLabel,
['aria-label']: ariaLabel,
ariaLabel: deprecatedAriaLabel,
children,
role,
onActionButtonClick,
Expand Down Expand Up @@ -637,7 +678,7 @@ export function ActionableNotification({

{!hideCloseButton && (
<NotificationButton
aria-label={ariaLabel}
aria-label={deprecatedAriaLabel || ariaLabel}
notificationType="actionable"
onClick={handleCloseButtonClick}
/>
Expand All @@ -655,7 +696,16 @@ ActionableNotification.propTypes = {
/**
* Provide a description for "close" icon button that can be read by screen readers
*/
ariaLabel: PropTypes.string,
['aria-label']: PropTypes.string,

/**
* Deprecated, please use `aria-label` instead.
* Provide a description for "close" icon button that can be read by screen readers
*/
ariaLabel: deprecate(
PropTypes.string,
'This prop syntax has been deprecated. Please use the new `aria-label`.'
),

/**
* Specify the content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
kind: 'error',
lowContrast: false,
hideCloseButton: false,
ariaLabel: 'closes notification',
['aria-label']: 'closes notification',
statusIconDescription: 'notification',
onClose: action('onClose'),
onCloseButtonClick: action('onCloseButtonClick'),
Expand All @@ -43,6 +43,11 @@ export const Default = () => (
export const Playground = (args) => <ActionableNotification {...args} />;

Playground.argTypes = {
['aria-label']: {
table: {
disable: true,
},
},
ariaLabel: {
table: {
disable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
kind: 'error',
lowContrast: false,
hideCloseButton: false,
ariaLabel: 'closes notification',
['aria-label']: 'closes notification',
francinelucca marked this conversation as resolved.
Show resolved Hide resolved
statusIconDescription: 'notification',
onClose: action('onClose'),
onCloseButtonClick: action('onCloseButtonClick'),
Expand All @@ -45,6 +45,11 @@ Playground.argTypes = {
disable: true,
},
},
['aria-label']: {
table: {
disable: true,
},
},
ariaLabel: {
table: {
disable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
kind: 'error',
lowContrast: false,
hideCloseButton: false,
ariaLabel: 'closes notification',
['aria-label']: 'closes notification',
statusIconDescription: 'notification',
onClose: action('onClose'),
onCloseButtonClick: action('onCloseButtonClick'),
Expand All @@ -48,6 +48,11 @@ Playground.argTypes = {
disable: true,
},
},
['aria-label']: {
table: {
disable: true,
},
},
ariaLabel: {
table: {
disable: true,
Expand Down