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

feat(TextLink): accesibility improvements #1072

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/text-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface CommonProps {
style?: React.CSSProperties;
classes?: {[className: string]: string};
disabled?: boolean;
'aria-label'?: string;
trackingEvent?: TrackingEvent | ReadonlyArray<TrackingEvent>;
trackEvent?: boolean;
/** "data-" prefix is automatically added. For example, use "testid" instead of "data-testid" */
Expand Down
4 changes: 4 additions & 0 deletions src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TEXTS_ES = {
disablePasswordVisibility: 'Ocultar contraseña',
loading: 'Cargando',
linkOpensInNewTab: 'Se abre en ventana nueva',
linkOpensInCurrentPage: 'página actual',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for real translations:
https://jira.tid.es/browse/LOC-1503

modalClose: 'Cerrar',
dialogCancelButton: 'Cancelar',
dialogAcceptButton: 'Aceptar',
Expand Down Expand Up @@ -60,6 +61,7 @@ const TEXTS_EN: ThemeTexts = {
disablePasswordVisibility: 'Hide password',
loading: 'Loading',
linkOpensInNewTab: 'Opens in a new window',
linkOpensInCurrentPage: 'current page',
modalClose: 'Close',
dialogCancelButton: 'Cancel',
dialogAcceptButton: 'Accept',
Expand Down Expand Up @@ -107,6 +109,7 @@ const TEXTS_DE: ThemeTexts = {
disablePasswordVisibility: 'Passwort verbergen',
loading: 'Wird gespeichert',
linkOpensInNewTab: 'Wird in neuem Fenster geöffnet',
linkOpensInCurrentPage: 'aktuelle Seite',
modalClose: 'Schließen',
dialogCancelButton: 'Abbrechen',
dialogAcceptButton: 'Akzeptieren',
Expand Down Expand Up @@ -154,6 +157,7 @@ const TEXTS_PT: ThemeTexts = {
disablePasswordVisibility: 'esconder a senha',
loading: 'Carregando',
linkOpensInNewTab: 'Abre em nova janela',
linkOpensInCurrentPage: 'página atual',
modalClose: 'Fechar',
dialogCancelButton: 'Cancelar',
dialogAcceptButton: 'Aceitar',
Expand Down
9 changes: 7 additions & 2 deletions src/touchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const RawTouchable = React.forwardRef<TouchableElement, Props>((props, ref) => {
const type = props.type ? props.type : 'button';

const openNewTab = !!props.href && !!props.newTab;
const openInCurrentPage = props.href?.startsWith('#');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is enough, wdyt?

Copy link
Member

@pladaria pladaria Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a counterexample

const loadOnTop = !openNewTab && !!props.href && !!props.loadOnTop;

const stopPropagationIfNeeded = (event: React.MouseEvent<HTMLElement>) => {
Expand Down Expand Up @@ -226,11 +227,15 @@ const RawTouchable = React.forwardRef<TouchableElement, Props>((props, ref) => {
ref={ref as React.RefObject<HTMLAnchorElement>}
>
{children}
{openNewTab && (
{openNewTab ? (
<ScreenReaderOnly>
<span>{texts.linkOpensInNewTab}</span>
</ScreenReaderOnly>
)}
) : openInCurrentPage ? (
<ScreenReaderOnly>
<span>{texts.linkOpensInCurrentPage}</span>
</ScreenReaderOnly>
) : null}
</a>
);
}
Expand Down
Loading