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/use visually hidden component #1045

Merged
merged 2 commits into from
Sep 8, 2023
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
{{ _disabledAttr }}
>
{% if _labelRendered %}
<legend class="accessibility-hidden">
<VisuallyHidden elementType="legend">
{{- _labelRendered -}}
</legend>
</VisuallyHidden>
{% if not _isLabelHidden %}
<div {{ classProp(_labelClassNames) }} aria-hidden="true">
{{- _labelRendered -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{% if _onEdit %}
<span class="FileUploaderAttachment__slot">
<button type="button" class="FileUploaderAttachment__action" onclick="{{ _onEdit }}">
<span class="accessibility-hidden">{{ _editText }}</span>
<VisuallyHidden>{{ _editText }}</VisuallyHidden>
<Icon name="edit" isReusable={ false } />
</button>
</span>
Expand All @@ -55,7 +55,7 @@
class="{{ _removeClassName }}"
data-spirit-populate-field="button"
>
<span class="accessibility-hidden">{{ _removeText }}</span>
<VisuallyHidden>{{ _removeText }}</VisuallyHidden>
<Icon name="close" isReusable={ false } />
</button>
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
aria-expanded="false"
>
<Icon name="close" />
<span class="accessibility-hidden">{{ _label }}</span>
<VisuallyHidden>{{ _label }}</VisuallyHidden>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
isSquare
>
<Icon name="hamburger" />
<span class="accessibility-hidden">{{ _menuToggleLabel }}</span>
<VisuallyHidden>{{ _menuToggleLabel }}</VisuallyHidden>
</Button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
isSquare
>
<Icon name="close" />
<span class="accessibility-hidden">{{ _closeLabel }}</span>
<VisuallyHidden>{{ _closeLabel }}</VisuallyHidden>
</Button>
</header>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
{{ _targetAttr }}
{{ _typeAttr | raw }}
>
<span class="accessibility-hidden">{{ _accessibilityLabel }}</span>
<VisuallyHidden>{{ _accessibilityLabel }}</VisuallyHidden>
<span aria-hidden="true">{{ _pageNumber }}</span>
</{{ _elementType }}>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
}) } %}
{% block content %}
<Icon name="chevron-right" />
<span class="accessibility-hidden">{{ _accessibilityLabel }}</span>
<VisuallyHidden>{{ _accessibilityLabel }}</VisuallyHidden>
{% endblock %}
{% endembed %}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
}) } %}
{% block content %}
<Icon name="chevron-left" />
<span class="accessibility-hidden">{{ _accessibilityLabel }}</span>
<VisuallyHidden>{{ _accessibilityLabel }}</VisuallyHidden>
{% endblock %}
{% endembed %}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
aria-expanded="true"
>
<Icon name="close" aria-hidden="true" />
<span class="accessibility-hidden">{{ _closeLabel }}</span>
<VisuallyHidden>{{ _closeLabel }}</VisuallyHidden>
</button>
{% endif %}
<span class="{{ _arrowClassName }}"></span>
Expand Down