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

AC-2479::Visual text label does not match accessible name. (Global He… #3932

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
"accountMenuRef": "elementRef",
"accountMenuTriggerRef": [MockFunction],
"handleTriggerClick": [Function],
"isUserSignedIn": true,
"setAccountMenuIsOpen": [MockFunction],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ jest.mock('@magento/peregrine/lib/hooks/useDropdown', () => ({
})
}));

jest.mock('@magento/peregrine/lib/context/user', () => {
const state = {
isSignedIn: true
};
const api = {};
const useUserContext = jest.fn(() => [state, api]);

return { useUserContext };
});

const defaultProps = {
VIEWS: {
SIGNIN: 'SIGNIN',
Expand Down
7 changes: 5 additions & 2 deletions packages/peregrine/lib/talons/Header/useAccountTrigger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';

import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown';

import { useUserContext } from '@magento/peregrine/lib/context/user';
/**
* The useAccountTrigger talon complements the AccountTrigger component.
*
Expand All @@ -25,11 +25,14 @@ export const useAccountTrigger = () => {
setAccountMenuIsOpen(isOpen => !isOpen);
}, [setAccountMenuIsOpen]);

const [{ isSignedIn: isUserSignedIn }] = useUserContext();

return {
accountMenuIsOpen,
accountMenuRef,
accountMenuTriggerRef,
setAccountMenuIsOpen,
handleTriggerClick
handleTriggerClick,
isUserSignedIn
};
};
3 changes: 2 additions & 1 deletion packages/venia-ui/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"accountMenu.savedPaymentsLink": "Saved Payments",
"accountMenu.signOutButtonText": "Sign Out",
"accountMenu.storeCreditLink": "Store Credit & Gift Cards",
"accountTrigger.ariaLabel": "Toggle My Account Menu",
"accountTrigger.ariaLabelMyMenu": "Toggle My Account Menu",
"accountTrigger.ariaLabelSignIn": "Sign In",
"accountTrigger.buttonFallback": "Sign In",
"accountTrigger.signIn": "Sign In",
"addressBook.addNewAddresstext": "Add New Address",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`it renders a loading indicator when appropriate 1`] = `
</span>
<span
aria-atomic="true"
aria-label="Toggle My Account Menu"
aria-live="polite"
className="text"
>
Expand Down
8 changes: 8 additions & 0 deletions packages/venia-ui/lib/components/AccountChip/accountChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const AccountChip = props => {
const classes = useStyle(defaultClasses, props.classes);
const { formatMessage } = useIntl();

const ariaLabelMyMenu = formatMessage({
id: 'accountTrigger.ariaLabelMyMenu',
defaultMessage: 'Toggle My Account Menu'
});

const ariaLabel = isUserSignedIn ? ariaLabelMyMenu : '';

let chipText;
if (!isUserSignedIn) {
chipText = fallbackText;
Expand All @@ -55,6 +62,7 @@ const AccountChip = props => {
<span className={classes.root}>
<Icon src={AccountIcon} />
<span
aria-label={ariaLabel}
aria-atomic="true"
aria-live="polite"
data-cy="AccountChip-text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Array [
>
<button
aria-expanded={false}
aria-label="Toggle My Account Menu"
aria-label="Sign In"
className="trigger"
onClick={[MockFunction handleTriggerClick]}
>
Expand Down
17 changes: 12 additions & 5 deletions packages/venia-ui/lib/components/Header/accountTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,29 @@ const AccountTrigger = props => {
accountMenuRef,
accountMenuTriggerRef,
setAccountMenuIsOpen,
handleTriggerClick
handleTriggerClick,
isUserSignedIn
} = talonProps;

const classes = useStyle(defaultClasses, props.classes);
const rootClassName = accountMenuIsOpen ? classes.root_open : classes.root;
const { formatMessage } = useIntl();

const ariaLabelMyMenu = formatMessage({
id: 'accountTrigger.ariaLabelMyMenu',
defaultMessage: 'Toggle My Account Menu'
});
const ariaLabelSignIn = formatMessage({
id: 'accountTrigger.ariaLabelSignIn',
defaultMessage: 'Sign In'
});
const ariaLabel = isUserSignedIn ? ariaLabelMyMenu : ariaLabelSignIn;
return (
<Fragment>
<div className={rootClassName} ref={accountMenuTriggerRef}>
<button
aria-label={ariaLabel}
aria-expanded={accountMenuIsOpen}
aria-label={formatMessage({
id: 'accountTrigger.ariaLabel',
defaultMessage: 'Toggle My Account Menu'
})}
className={classes.trigger}
onClick={handleTriggerClick}
data-cy="AccountTrigger-trigger"
Expand Down