fix accessibility issue on rewards page #5991

This commit is contained in:
btzr-io 2021-07-20 12:14:28 -05:00
parent ba763a85cd
commit bc2a8ba77d
5 changed files with 25 additions and 13 deletions

View file

@ -206,14 +206,13 @@ function ClaimPreviewTile(props: Props) {
return ( return (
<li <li
role="link"
onClick={handleClick} onClick={handleClick}
className={classnames('card claim-preview--tile', { className={classnames('card claim-preview--tile', {
'claim-preview__wrapper--channel': isChannel, 'claim-preview__wrapper--channel': isChannel,
'claim-preview__live': live, 'claim-preview__live': live,
})} })}
> >
<NavLink aria-hidden tabIndex={-1} {...navLinkProps}> <NavLink {...navLinkProps} role="none" tabIndex={-1} aria-hidden>
<FileThumbnail thumbnail={thumbnailUrl} allowGifs> <FileThumbnail thumbnail={thumbnailUrl} allowGifs>
{!isChannel && ( {!isChannel && (
<React.Fragment> <React.Fragment>

View file

@ -70,9 +70,9 @@ const SkipNavigationButton = () => {
const skipNavigation = (e) => { const skipNavigation = (e) => {
// Match any focusable element // Match any focusable element
const focusableElementQuery = ` const focusableElementQuery = `
#main-content [tabindex]:not([tabIndex="-1"]):not(:disabled), #main-content [tabindex]:not([tabindex="-1"]):not(:disabled),
#main-content a:not([aria-hidden]):not([tabIndex="-1"]):not(:disabled), #main-content a:not([aria-hidden]):not([tabindex="-1"]):not(:disabled),
#main-content button:not([aria-hidden]):not([tabIndex="-1"]):not(:disabled) #main-content button:not([aria-hidden]):not([tabindex="-1"]):not(:disabled)
`; `;
// Find first focusable element // Find first focusable element
const element = document.querySelector(focusableElementQuery); const element = document.querySelector(focusableElementQuery);

View file

@ -13,11 +13,12 @@ type Props = {
label: ?string, label: ?string,
reward: Reward, reward: Reward,
button: ?boolean, button: ?boolean,
disabled: boolean,
claimReward: (Reward) => void, claimReward: (Reward) => void,
}; };
const RewardLink = (props: Props) => { const RewardLink = (props: Props) => {
const { reward, claimReward, label, isPending, button } = props; const { reward, claimReward, label, isPending, button, disabled = false } = props;
let displayLabel = label; let displayLabel = label;
if (isPending) { if (isPending) {
displayLabel = __('Claiming...'); displayLabel = __('Claiming...');
@ -34,7 +35,7 @@ const RewardLink = (props: Props) => {
return !reward ? null : ( return !reward ? null : (
<Button <Button
button={button ? 'primary' : 'link'} button={button ? 'primary' : 'link'}
disabled={isPending} disabled={disabled || isPending}
label={<LbcMessage>{displayLabel}</LbcMessage>} label={<LbcMessage>{displayLabel}</LbcMessage>}
aria-label={displayLabel} aria-label={displayLabel}
onClick={() => { onClick={() => {

View file

@ -23,10 +23,11 @@ type Props = {
claim_code: string, claim_code: string,
}, },
user: User, user: User,
disabled: boolean,
}; };
const RewardTile = (props: Props) => { const RewardTile = (props: Props) => {
const { reward, openRewardCodeModal, openSetReferrerModal, user } = props; const { reward, openRewardCodeModal, openSetReferrerModal, user, disabled = false } = props;
const referrerSet = user && user.invited_by_id; const referrerSet = user && user.invited_by_id;
const claimed = !!reward.transaction_id; const claimed = !!reward.transaction_id;
const customActionsRewards = [rewards.TYPE_REFERRAL, rewards.TYPE_REFEREE]; const customActionsRewards = [rewards.TYPE_REFERRAL, rewards.TYPE_REFEREE];
@ -38,18 +39,25 @@ const RewardTile = (props: Props) => {
actions={ actions={
<div className="section__actions"> <div className="section__actions">
{reward.reward_type === rewards.TYPE_GENERATED_CODE && ( {reward.reward_type === rewards.TYPE_GENERATED_CODE && (
<Button button="primary" onClick={openRewardCodeModal} label={__('Enter Code')} /> <Button button="primary" onClick={openRewardCodeModal} label={__('Enter Code')} disabled={disabled} />
)} )}
{reward.reward_type === rewards.TYPE_REFERRAL && ( {reward.reward_type === rewards.TYPE_REFERRAL && (
<Button button="primary" navigate="/$/invite" label={__('Go To Invites')} /> <Button
button="primary"
navigate="/$/invite"
label={__('Go To Invites')}
aria-hidden={disabled}
tabIndex={disabled ? -1 : 0}
/>
)} )}
{reward.reward_type === rewards.TYPE_REFEREE && ( {reward.reward_type === rewards.TYPE_REFEREE && (
<> <>
{referrerSet && <RewardLink button reward_type={reward.reward_type} />} {referrerSet && <RewardLink button reward_type={reward.reward_type} disabled={disabled} />}
<Button <Button
button={referrerSet ? 'link' : 'primary'} button={referrerSet ? 'link' : 'primary'}
onClick={openSetReferrerModal} onClick={openSetReferrerModal}
label={referrerSet ? __('Change Inviter') : __('Set Inviter')} label={referrerSet ? __('Change Inviter') : __('Set Inviter')}
disabled={disabled}
/> />
</> </>
)} )}
@ -59,7 +67,7 @@ const RewardTile = (props: Props) => {
<Icon icon={ICONS.COMPLETED} /> {__('Reward claimed.')} <Icon icon={ICONS.COMPLETED} /> {__('Reward claimed.')}
</span> </span>
) : ( ) : (
<RewardLink button claim_code={reward.claim_code} /> <RewardLink button claim_code={reward.claim_code} disabled={disabled} />
))} ))}
</div> </div>
} }

View file

@ -102,6 +102,8 @@ class RewardsPage extends PureComponent<Props> {
} }
renderCustomRewardCode() { renderCustomRewardCode() {
const { user } = this.props;
const isNotEligible = !user || !user.primary_email || !user.has_verified_email || !user.is_reward_approved;
return ( return (
<RewardTile <RewardTile
key={REWARD_TYPES.TYPE_GENERATED_CODE} key={REWARD_TYPES.TYPE_GENERATED_CODE}
@ -110,6 +112,7 @@ class RewardsPage extends PureComponent<Props> {
reward_title: __('Custom Code'), reward_title: __('Custom Code'),
reward_description: __('Are you a supermodel or rockstar that received a custom reward code? Claim it here.'), reward_description: __('Are you a supermodel or rockstar that received a custom reward code? Claim it here.'),
}} }}
disabled={isNotEligible}
/> />
); );
} }
@ -155,12 +158,13 @@ class RewardsPage extends PureComponent<Props> {
return ( return (
<div <div
aria-hidden={isNotEligible}
className={classnames('card__list', { className={classnames('card__list', {
'card--disabled': isNotEligible, 'card--disabled': isNotEligible,
})} })}
> >
{rewards.map((reward) => ( {rewards.map((reward) => (
<RewardTile key={reward.claim_code} reward={reward} /> <RewardTile disabled={isNotEligible} key={reward.claim_code} reward={reward} />
))} ))}
{this.renderCustomRewardCode()} {this.renderCustomRewardCode()}
</div> </div>