From ed302bc2750cd4f8cb49b07f745a55f345164cd2 Mon Sep 17 00:00:00 2001 From: literat Date: Thu, 7 Sep 2023 13:21:36 +0200 Subject: [PATCH 1/2] Refactor(web-react): Use `VisuallyHidden` component instead of className refs #DS-926 --- .../web-react/src/components/FieldGroup/FieldGroup.tsx | 9 +++++---- .../components/FileUploader/AttachmentActionButton.tsx | 7 ++++--- .../components/FileUploader/AttachmentDismissButton.tsx | 7 ++++--- .../src/components/Header/HeaderDialogCloseButton.tsx | 9 +++++---- .../src/components/Header/HeaderMobileActions.tsx | 9 +++++---- packages/web-react/src/components/Modal/ModalHeader.tsx | 9 +++++---- .../src/components/Pagination/PaginationButtonLink.tsx | 3 ++- .../src/components/Pagination/PaginationLink.tsx | 7 ++++--- .../src/components/Tooltip/TooltipCloseButton.tsx | 7 ++++--- 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/packages/web-react/src/components/FieldGroup/FieldGroup.tsx b/packages/web-react/src/components/FieldGroup/FieldGroup.tsx index 49bc7e34e4..3a70e4918d 100644 --- a/packages/web-react/src/components/FieldGroup/FieldGroup.tsx +++ b/packages/web-react/src/components/FieldGroup/FieldGroup.tsx @@ -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 { @@ -35,7 +36,7 @@ const FieldGroup = (props: SpiritFieldGroupProps) => { className={classNames(classProps.root, styleProps.className)} disabled={isDisabled} > - {label} + {label} {!isLabelHidden && ( ); diff --git a/packages/web-react/src/components/Modal/ModalHeader.tsx b/packages/web-react/src/components/Modal/ModalHeader.tsx index bcb1519bb7..b994c47593 100644 --- a/packages/web-react/src/components/Modal/ModalHeader.tsx +++ b/packages/web-react/src/components/Modal/ModalHeader.tsx @@ -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; @@ -31,7 +32,7 @@ const ModalHeader = (props: ModalHeaderProps) => { aria-controls={id} > - {closeLabel} + {closeLabel} ); diff --git a/packages/web-react/src/components/Pagination/PaginationButtonLink.tsx b/packages/web-react/src/components/Pagination/PaginationButtonLink.tsx index ee3efedacd..066b14540f 100644 --- a/packages/web-react/src/components/Pagination/PaginationButtonLink.tsx +++ b/packages/web-react/src/components/Pagination/PaginationButtonLink.tsx @@ -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'] }] */ @@ -19,7 +20,7 @@ const _PaginationButtonLink = ( return ( - {accessibilityLabel} + {accessibilityLabel} ); }; diff --git a/packages/web-react/src/components/Pagination/PaginationLink.tsx b/packages/web-react/src/components/Pagination/PaginationLink.tsx index 7e07daa0a2..84147a3c3a 100644 --- a/packages/web-react/src/components/Pagination/PaginationLink.tsx +++ b/packages/web-react/src/components/Pagination/PaginationLink.tsx @@ -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 */ @@ -22,7 +23,7 @@ const _PaginationLink = ( {...styleProps} className={classNames(classProps.link, styleProps.className)} > - {accessibilityLabel} + {accessibilityLabel} ); diff --git a/packages/web-react/src/components/Tooltip/TooltipCloseButton.tsx b/packages/web-react/src/components/Tooltip/TooltipCloseButton.tsx index 9768ab3c18..60f739ed59 100644 --- a/packages/web-react/src/components/Tooltip/TooltipCloseButton.tsx +++ b/packages/web-react/src/components/Tooltip/TooltipCloseButton.tsx @@ -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) => { @@ -18,7 +19,7 @@ const TooltipCloseButton = ({ label = 'Close', onClick, ...restProps }: TooltipC aria-expanded="true" >