Skip to content

Commit

Permalink
Refactor(web-react): Use VisuallyHidden component instead of className
Browse files Browse the repository at this point in the history
refs #DS-926
  • Loading branch information
literat committed Sep 8, 2023
1 parent e987ea3 commit ed302bc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
9 changes: 5 additions & 4 deletions packages/web-react/src/components/FieldGroup/FieldGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import classNames from 'classnames';
import { useFieldGroupStyleProps } from './useFieldGroupStyleProps';
import { SpiritFieldGroupProps } from '../../types';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritFieldGroupProps } from '../../types';
import { useValidationText } from '../Field/useValidationText';
import { VisuallyHidden } from '../VisuallyHidden';
import { useFieldGroupStyleProps } from './useFieldGroupStyleProps';

const FieldGroup = (props: SpiritFieldGroupProps) => {
const {
Expand Down Expand Up @@ -35,7 +36,7 @@ const FieldGroup = (props: SpiritFieldGroupProps) => {
className={classNames(classProps.root, styleProps.className)}
disabled={isDisabled}
>
<legend className="accessibility-hidden">{label}</legend>
<VisuallyHidden elementType="legend">{label}</VisuallyHidden>
{!isLabelHidden && (
<div className={classProps.label} aria-hidden="true">
{label}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritAttachmentActionButtonProps } from '../../types';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useFileUploaderStyleProps } from './useFileUploaderStyleProps';
import { useStyleProps } from '../../hooks';

const AttachmentActionButton = (props: SpiritAttachmentActionButtonProps) => {
const { name = 'edit', children, ...restProps } = props;
Expand All @@ -18,7 +19,7 @@ const AttachmentActionButton = (props: SpiritAttachmentActionButtonProps) => {
{...styleProps}
className={classNames(classProps.attachment.button, styleProps.className)}
>
<span className="accessibility-hidden">{children}</span>
<VisuallyHidden>{children}</VisuallyHidden>
<Icon name={name} aria-hidden="true" />
</button>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritAttachmentDismissButtonProps } from '../../types';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useFileUploaderStyleProps } from './useFileUploaderStyleProps';
import { useStyleProps } from '../../hooks';

const AttachmentDismissButton = (props: SpiritAttachmentDismissButtonProps) => {
const { children, ...restProps } = props;
Expand All @@ -18,7 +19,7 @@ const AttachmentDismissButton = (props: SpiritAttachmentDismissButtonProps) => {
{...styleProps}
className={classNames(classProps.attachment.button, styleProps.className)}
>
<span className="accessibility-hidden">{children}</span>
<VisuallyHidden>{children}</VisuallyHidden>
<Icon name="close" aria-hidden="true" />
</button>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { ClickEvent, HeaderDialogCloseButtonProps } from '../../types';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useHeaderDialogContext } from './HeaderDialogContext';
import { HEADER_DIALOG_CLOSE_BUTTON_LABEL_DEFAULT } from './constants';
import { useHeaderStyleProps } from './useHeaderStyleProps';
import { useHeaderDialogContext } from './HeaderDialogContext';
import { Icon } from '../Icon';

const HeaderDialogCloseButton = (props: HeaderDialogCloseButtonProps) => {
const { label = HEADER_DIALOG_CLOSE_BUTTON_LABEL_DEFAULT, onClick, ...restProps } = props;
Expand All @@ -30,7 +31,7 @@ const HeaderDialogCloseButton = (props: HeaderDialogCloseButtonProps) => {
style={styleProps.style}
>
<Icon name="close" />
<span className="accessibility-hidden">{label}</span>
<VisuallyHidden>{label}</VisuallyHidden>
</button>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { HeaderMobileActionsProps } from '../../types';
import { HEADER_MENU_TOGGLE_LABEL_DEFAULT } from './constants';
import { useHeaderStyleProps } from './useHeaderStyleProps';
import { Button } from '../Button';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { HEADER_MENU_TOGGLE_LABEL_DEFAULT } from './constants';
import { useHeaderStyleProps } from './useHeaderStyleProps';

const HeaderMobileActions = (props: HeaderMobileActionsProps) => {
const {
Expand All @@ -29,7 +30,7 @@ const HeaderMobileActions = (props: HeaderMobileActionsProps) => {
{children}
<Button aria-controls={dialogId} aria-expanded={isOpen} color="inverted" onClick={onOpen} isSquare>
<Icon name="hamburger" />
<span className="accessibility-hidden">{menuToggleLabel}</span>
<VisuallyHidden>{menuToggleLabel}</VisuallyHidden>
</Button>
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions packages/web-react/src/components/Modal/ModalHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { ClickEvent, ModalHeaderProps } from '../../types';
import { useModalStyleProps } from './useModalStyleProps';
import { useModalContext } from './ModalContext';
import { Button } from '../Button';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useModalContext } from './ModalContext';
import { useModalStyleProps } from './useModalStyleProps';

const ModalHeader = (props: ModalHeaderProps) => {
const { children, closeLabel = 'Close', ...restProps } = props;
Expand All @@ -31,7 +32,7 @@ const ModalHeader = (props: ModalHeaderProps) => {
aria-controls={id}
>
<Icon name="close" />
<span className="accessibility-hidden">{closeLabel}</span>
<VisuallyHidden>{closeLabel}</VisuallyHidden>
</Button>
</header>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { ElementType, ForwardedRef, forwardRef } from 'react';
import { SpiritPaginationButtonLinkProps } from '../../types';
import { ButtonLink } from '../Button';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';

/* We need an exception for components exported with forwardRef */
/* eslint no-underscore-dangle: ['error', { allow: ['_PaginationButtonLink'] }] */
Expand All @@ -19,7 +20,7 @@ const _PaginationButtonLink = <E extends ElementType = 'a'>(
return (
<ButtonLink color="secondary" isSquare {...restProps} ref={ref}>
<Icon name={iconType[direction]} />
<span className="accessibility-hidden">{accessibilityLabel}</span>
<VisuallyHidden>{accessibilityLabel}</VisuallyHidden>
</ButtonLink>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { ElementType, ForwardedRef, forwardRef } from 'react';
import classNames from 'classnames';
import { SpiritPaginationLinkProps } from '../../types';
import React, { ElementType, ForwardedRef, forwardRef } from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritPaginationLinkProps } from '../../types';
import { VisuallyHidden } from '../VisuallyHidden';
import { usePaginationStyleProps } from './usePaginationStyleProps';

/* We need an exception for components exported with forwardRef */
Expand All @@ -22,7 +23,7 @@ const _PaginationLink = <E extends ElementType = 'a'>(
{...styleProps}
className={classNames(classProps.link, styleProps.className)}
>
<span className="accessibility-hidden">{accessibilityLabel}</span>
<VisuallyHidden>{accessibilityLabel}</VisuallyHidden>
<span aria-hidden="true">{pageNumber}</span>
</ElementTag>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { Icon } from '../Icon';
import { TooltipCloseButtonProps } from '../../types';
import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useTooltipStyleProps } from './useTooltipStyleProps';

const TooltipCloseButton = ({ label = 'Close', onClick, ...restProps }: TooltipCloseButtonProps) => {
Expand All @@ -18,7 +19,7 @@ const TooltipCloseButton = ({ label = 'Close', onClick, ...restProps }: TooltipC
aria-expanded="true"
>
<Icon name="close" aria-hidden="true" />
<span className="accessibility-hidden">{label}</span>
<VisuallyHidden>{label}</VisuallyHidden>
</button>
);
};
Expand Down

0 comments on commit ed302bc

Please sign in to comment.