From d74fbd4f899251afcae000b9fca31aec105a1470 Mon Sep 17 00:00:00 2001 From: Martyanov Andrey <37772440+martyanovandrey@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:47:51 +0500 Subject: [PATCH] fix: settings a11y - delete unnecessary aria-expanded (#281) * fix: settings a11y * lint --- .../LangControl/LangControl.tsx | 3 - .../SettingsControl/SettingsControl.tsx | 23 +++++-- src/components/Feedback/Feedback.tsx | 4 -- .../Feedback/controls/DislikeControl.tsx | 61 +++++++--------- .../Feedback/controls/LikeControl.tsx | 69 +++++++++---------- src/components/Subscribe/Subscribe.tsx | 67 ++++++++---------- 6 files changed, 102 insertions(+), 125 deletions(-) diff --git a/src/components/Controls/single-controls/LangControl/LangControl.tsx b/src/components/Controls/single-controls/LangControl/LangControl.tsx index 0997cdf0..5e1621d3 100644 --- a/src/components/Controls/single-controls/LangControl/LangControl.tsx +++ b/src/components/Controls/single-controls/LangControl/LangControl.tsx @@ -117,9 +117,6 @@ const LangControl = (props: ControlProps) => { tooltipText={t('lang-text')} icon={Globe} popupPosition={popupPosition} - buttonExtraProps={{ - 'aria-expanded': popupState.visible, - }} isTooltipHidden={popupState.visible} /> diff --git a/src/components/Controls/single-controls/SettingsControl/SettingsControl.tsx b/src/components/Controls/single-controls/SettingsControl/SettingsControl.tsx index f94f3061..2d6eac38 100644 --- a/src/components/Controls/single-controls/SettingsControl/SettingsControl.tsx +++ b/src/components/Controls/single-controls/SettingsControl/SettingsControl.tsx @@ -92,7 +92,13 @@ const SettingsControl = (props: ControlProps) => { description: t( `description_wide_format_${wideFormat ? 'enabled' : 'disabled'}`, ), - control: , + control: ( + + ), } : null, onChangeShowMiniToc @@ -104,6 +110,7 @@ const SettingsControl = (props: ControlProps) => { ), control: ( { Theme.Light === theme ? t('description_disabled_dark_theme') : t('description_enabled_dark_theme'), - control: , + control: ( + + ), } : null, onChangeTextSize @@ -135,13 +148,14 @@ const SettingsControl = (props: ControlProps) => { })} view="flat" onClick={_onChangeTextSize(textSizeKey)} + title={`${t('label_text_size')} ${t(`description_${textSizeKey}_text_size`)}`} > - A + A ))} @@ -218,9 +232,6 @@ const SettingsControl = (props: ControlProps) => { tooltipText={t('settings-text')} popupPosition={popupPosition} icon={Gear} - buttonExtraProps={{ - 'aria-expanded': isVisiblePopup, - }} isTooltipHidden={isVisiblePopup} /> diff --git a/src/components/Feedback/Feedback.tsx b/src/components/Feedback/Feedback.tsx index a5c14d98..b0fb1b0f 100644 --- a/src/components/Feedback/Feedback.tsx +++ b/src/components/Feedback/Feedback.tsx @@ -112,8 +112,6 @@ const Feedback: React.FC = (props) => { [onSendFeedback, setInnerState, dislikeSuccessPopup, hideFeedbackPopups], ); - const isDislikePopupVisible = dislikeSuccessPopup.visible || dislikeVariantsPopup.visible; - return ( @@ -122,14 +120,12 @@ const Feedback: React.FC = (props) => { view={view} onClick={onChangeLike} isLiked={innerState === FeedbackType.like} - isPopupVisible={likeSuccessPopup.visible} /> {likeControlRef.current && ( diff --git a/src/components/Feedback/controls/DislikeControl.tsx b/src/components/Feedback/controls/DislikeControl.tsx index 330d8207..d25e13b2 100644 --- a/src/components/Feedback/controls/DislikeControl.tsx +++ b/src/components/Feedback/controls/DislikeControl.tsx @@ -11,7 +11,6 @@ import {FeedbackView} from '../Feedback'; type DislikeControlProps = { isVerticalView?: boolean | undefined; isDisliked: boolean | undefined; - isPopupVisible: boolean; className?: string | undefined; view: FeedbackView | undefined; onClick: () => void; @@ -20,45 +19,35 @@ type DislikeControlProps = { const b = block('dc-feedback'); const DislikeControl = memo( - forwardRef( - ({isDisliked, isPopupVisible, view, onClick}, ref) => { - const {t} = useTranslation('feedback'); - const {isVerticalView, controlClassName} = useContext(ControlsLayoutContext); - const tooltipText = isDisliked ? t('cancel-dislike-text') : t('dislike-text'); + forwardRef(({isDisliked, view, onClick}, ref) => { + const {t} = useTranslation('feedback'); + const {isVerticalView, controlClassName} = useContext(ControlsLayoutContext); + const tooltipText = isDisliked ? t('cancel-dislike-text') : t('dislike-text'); - const Icon = isDisliked ? ThumbsDownFill : ThumbsDown; - - if (view === FeedbackView.Wide) { - return ( - - ); - } + const Icon = isDisliked ? ThumbsDownFill : ThumbsDown; + if (view === FeedbackView.Wide) { return ( - + ); - }, - ), + } + + return ( + + ); + }), ); DislikeControl.displayName = 'DislikeControl'; diff --git a/src/components/Feedback/controls/LikeControl.tsx b/src/components/Feedback/controls/LikeControl.tsx index 342edb1f..14c4def5 100644 --- a/src/components/Feedback/controls/LikeControl.tsx +++ b/src/components/Feedback/controls/LikeControl.tsx @@ -13,7 +13,6 @@ import {FeedbackView} from '../Feedback'; type LikeControlProps = { isVerticalView?: boolean | undefined; isLiked: boolean | undefined; - isPopupVisible: boolean; className?: string | undefined; view: FeedbackView | undefined; onClick: () => void; @@ -23,48 +22,42 @@ type LikeControlProps = { const b = block('dc-feedback'); const LikeControl = memo( - forwardRef( - ({isLiked, isPopupVisible, view, onClick}, ref) => { - const {t} = useTranslation('feedback'); - const {isVerticalView, popupPosition, controlClassName} = - useContext(ControlsLayoutContext); - const tooltipText = isLiked ? t('cancel-like-text') : t('like-text'); + forwardRef(({isLiked, view, onClick}, ref) => { + const {t} = useTranslation('feedback'); + const {isVerticalView, popupPosition, controlClassName} = useContext(ControlsLayoutContext); + const tooltipText = isLiked ? t('cancel-like-text') : t('like-text'); - const Icon = isLiked ? ThumbsUpFill : ThumbsUp; - - if (view === FeedbackView.Wide) { - return ( - - ); - } + const Icon = isLiked ? ThumbsUpFill : ThumbsUp; + if (view === FeedbackView.Wide) { return ( - + onClick={onClick} + className={b('control', {view})} + > + + + + {t('button-like-text')} + ); - }, - ), + } + + return ( + + ); + }), ); LikeControl.displayName = 'LikeControl'; diff --git a/src/components/Subscribe/Subscribe.tsx b/src/components/Subscribe/Subscribe.tsx index 6fc326d1..4737f343 100644 --- a/src/components/Subscribe/Subscribe.tsx +++ b/src/components/Subscribe/Subscribe.tsx @@ -27,49 +27,43 @@ export interface SubscribeProps { type SubscribeControlProps = { view: SubscribeView; onChangeSubscribe: () => void; - isPopupVisible: boolean; }; const SubscribeControl = memo( - forwardRef( - ({view, onChangeSubscribe, isPopupVisible}, ref) => { - const {isVerticalView, popupPosition, controlClassName, controlSize} = - useContext(ControlsLayoutContext); - const {t} = useTranslation('controls'); - - if (view === SubscribeView.Wide) { - return ( - - ); - } + forwardRef(({view, onChangeSubscribe}, ref) => { + const {isVerticalView, popupPosition, controlClassName, controlSize} = + useContext(ControlsLayoutContext); + const {t} = useTranslation('controls'); + if (view === SubscribeView.Wide) { return ( - + className={b('control', {view})} + > + + + + {t('button-Subscribe-text')} + ); - }, - ), + } + + return ( + + ); + }), ); SubscribeControl.displayName = 'SubscribeControl'; @@ -113,8 +107,6 @@ const Subscribe = memo((props) => { successPopup.open(); }, [successPopup, variantsPopup]); - const isPopupVisible = successPopup.visible || variantsPopup.visible; - return ( @@ -122,7 +114,6 @@ const Subscribe = memo((props) => { ref={subscribeControlRef} view={view} onChangeSubscribe={onChangeSubscribe} - isPopupVisible={isPopupVisible} /> {successPopup.visible && subscribeControlRef.current && (