feat: session input show hide button improvments

better aria labeling and dataTestIds
pull/3083/head
William Grant 1 year ago
parent aa87675ad4
commit 273fc42be4

@ -160,11 +160,24 @@ const ErrorItem = (props: { id: string; error: string }) => {
); );
}; };
const ShowHideButton = (props: { type ShowHideStrings = { hide: string; show: string };
type ShowHideButtonProps = {
forceShow: boolean; forceShow: boolean;
toggleForceShow: () => void; toggleForceShow: () => void;
error: boolean; error: boolean;
}) => { ariaLabels?: ShowHideStrings;
dataTestIds?: ShowHideStrings;
};
const ShowHideButton = (props: ShowHideButtonProps) => {
const {
forceShow,
toggleForceShow,
error,
ariaLabels = { hide: 'Hide input text button', show: 'Show input text button' },
dataTestIds = { hide: 'hide-input-text-toggle', show: 'show-input-text-toggle' },
} = props;
const htmlDirection = useHTMLDirection(); const htmlDirection = useHTMLDirection();
const style: CSSProperties = { const style: CSSProperties = {
position: 'absolute', position: 'absolute',
@ -174,30 +187,29 @@ const ShowHideButton = (props: {
right: htmlDirection === 'ltr' ? 'var(--margins-sm)' : undefined, right: htmlDirection === 'ltr' ? 'var(--margins-sm)' : undefined,
}; };
if (props.forceShow) { if (forceShow) {
return ( return (
<SessionIconButton <SessionIconButton
ariaLabel={'Hide recovery phrase toggle'} ariaLabel={ariaLabels.hide}
iconType={'eyeDisabled'} iconType={'eyeDisabled'}
iconColor={props.error ? 'var(--danger-color)' : 'var(--text-primary-color)'} iconColor={error ? 'var(--danger-color)' : 'var(--text-primary-color)'}
iconSize="huge" iconSize="huge"
onClick={props.toggleForceShow} onClick={toggleForceShow}
style={style} style={style}
aria-label={'Show or hide input'} dataTestId={dataTestIds.hide}
dataTestId="hide-recovery-phrase-toggle"
/> />
); );
} }
return ( return (
<SessionIconButton <SessionIconButton
ariaLabel={'Reveal recovery phrase toggle'} ariaLabel={ariaLabels.show}
iconType={'eye'} iconType={'eye'}
iconColor={props.error ? 'var(--danger-color)' : 'var(--text-primary-color)'} iconColor={props.error ? 'var(--danger-color)' : 'var(--text-primary-color)'}
iconSize="huge" iconSize="huge"
onClick={props.toggleForceShow} onClick={toggleForceShow}
style={style} style={style}
dataTestId="reveal-recovery-phrase-toggle" dataTestId={dataTestIds.show}
/> />
); );
}; };
@ -213,7 +225,6 @@ type Props = {
placeholder?: string; placeholder?: string;
ariaLabel?: string; ariaLabel?: string;
maxLength?: number; maxLength?: number;
enableShowHide?: boolean;
onValueChanged?: (value: string) => any; onValueChanged?: (value: string) => any;
onEnterPressed?: (value: string) => any; onEnterPressed?: (value: string) => any;
autoFocus?: boolean; autoFocus?: boolean;
@ -221,6 +232,9 @@ type Props = {
inputRef?: any; inputRef?: any;
inputDataTestId?: string; inputDataTestId?: string;
id?: string; id?: string;
enableShowHide?: boolean;
showHideAriaLabels?: ShowHideStrings;
showHideDataTestIds?: ShowHideStrings;
ctaButton?: ReactNode; ctaButton?: ReactNode;
monospaced?: boolean; monospaced?: boolean;
textSize?: TextSizes; textSize?: TextSizes;
@ -239,7 +253,6 @@ export const SessionInput = (props: Props) => {
value, value,
ariaLabel, ariaLabel,
maxLength, maxLength,
enableShowHide,
error, error,
onValueChanged, onValueChanged,
onEnterPressed, onEnterPressed,
@ -248,6 +261,9 @@ export const SessionInput = (props: Props) => {
inputRef, inputRef,
inputDataTestId, inputDataTestId,
id = 'session-input-floating-label', id = 'session-input-floating-label',
enableShowHide,
showHideAriaLabels,
showHideDataTestIds,
ctaButton, ctaButton,
monospaced, monospaced,
textSize, textSize,
@ -368,6 +384,8 @@ export const SessionInput = (props: Props) => {
setForceShow(!forceShow); setForceShow(!forceShow);
}} }}
error={Boolean(errorString)} error={Boolean(errorString)}
ariaLabels={showHideAriaLabels}
dataTestIds={showHideDataTestIds}
/> />
)} )}
</StyledBorder> </StyledBorder>

@ -242,6 +242,14 @@ export const RestoreAccount = () => {
onEnterPressed={recoverAndFetchDisplayName} onEnterPressed={recoverAndFetchDisplayName}
error={recoveryPasswordError} error={recoveryPasswordError}
enableShowHide={true} enableShowHide={true}
showHideAriaLabels={{
hide: 'Hide recovery phrase toggle',
show: 'Reveal recovery phrase toggle',
}}
showHideDataTestIds={{
hide: 'hide-recovery-phrase-toggle',
show: 'reveal-recovery-phrase-toggle',
}}
inputDataTestId="recovery-phrase-input" inputDataTestId="recovery-phrase-input"
/> />
<SpacerLG /> <SpacerLG />

Loading…
Cancel
Save