From a01a52bd395b18a7b414480d788d6838262a4436 Mon Sep 17 00:00:00 2001 From: Victor Zeinstra Date: Thu, 19 Dec 2024 17:02:32 +0100 Subject: [PATCH] feat: rgaa link target title (#6367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: rgaa link target title * fix: link sur les pages générés * chore: clean * update links on fiche SP * only add title if target="_blank" * Update packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/ContentParser.tsx * update link * fix: rgga pour liens de la politique confidentialite * fix: rgaa titre de l'iframe non pertinent * fix: mention légal titre lien contact * chore: fix tests * fix: link politique confidentialite * fix: link mention legal * chore: snap --------- Co-authored-by: victor Co-authored-by: carolineBda Co-authored-by: Caroline <4971715+carolineBda@users.noreply.github.com> --- .../modules/code-du-travail/ContentParser.tsx | 4 ++-- .../src/modules/common/Link.tsx | 19 ++++++++++++++++ .../src/modules/common/LogoLink.tsx | 2 +- .../src/modules/config/DefaultLayout.tsx | 2 +- .../src/modules/config/StartDsfrDark.tsx | 2 +- .../src/modules/config/StartDsfrLight.tsx | 2 +- .../src/modules/config/StartDsfrSystem.tsx | 2 +- .../Agreements/AgreementsGlossaire.tsx | 2 +- .../Agreements/AgreementsIntro.tsx | 2 +- .../Agreements/AgreementsSection.tsx | 2 +- .../src/modules/error/NotFound.tsx | 2 +- .../fiche-ministere-travail/ContentParser.tsx | 10 +++++---- .../__tests__/ContentParser.test.tsx | 16 +++++++++++++- .../FicheServicePublic.test.tsx.snap | 8 +++++++ .../builder/components/LienExterne.tsx | 3 ++- .../builder/components/OuSAdresser.tsx | 3 ++- .../builder/components/ServiceEnLigne.tsx | 3 ++- .../builder/components/Video.tsx | 2 +- .../__snapshots__/Avertissement.test.tsx.snap | 2 ++ .../__snapshots__/LienExterne.test.tsx.snap | 2 ++ .../__snapshots__/OuSAdresser.test.tsx.snap | 1 + .../__snapshots__/Video.test.tsx.snap | 1 + .../src/modules/layout/ContainerWidget.tsx | 2 +- .../MentionsLegales.test.tsx.snap | 3 ++- .../src/modules/mentions-legales/index.tsx | 7 +++--- .../src/modules/plan-du-site/SiteMap.tsx | 2 +- .../modules/privacy-policy/TrackApproval.tsx | 2 +- .../src/modules/privacy-policy/index.tsx | 22 +++++++++---------- 28 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 packages/code-du-travail-frontend/src/modules/common/Link.tsx diff --git a/packages/code-du-travail-frontend/src/modules/code-du-travail/ContentParser.tsx b/packages/code-du-travail-frontend/src/modules/code-du-travail/ContentParser.tsx index dd4d2d4f28..9d16cb3e33 100644 --- a/packages/code-du-travail-frontend/src/modules/code-du-travail/ContentParser.tsx +++ b/packages/code-du-travail-frontend/src/modules/code-du-travail/ContentParser.tsx @@ -1,4 +1,5 @@ import parse, { domToReact } from "html-react-parser"; +import Link from "../common/Link"; export const ContentParser = ({ children, @@ -19,8 +20,7 @@ export const ContentParser = ({ const textToTrim = text[text.length - 1] === " "; return ( <> - {domToReact(domNode.children)} - + {domToReact(domNode.children)} {textToTrim ? " " : ""} ); diff --git a/packages/code-du-travail-frontend/src/modules/common/Link.tsx b/packages/code-du-travail-frontend/src/modules/common/Link.tsx new file mode 100644 index 0000000000..166849480b --- /dev/null +++ b/packages/code-du-travail-frontend/src/modules/common/Link.tsx @@ -0,0 +1,19 @@ +import React, { ReactNode } from "react"; +import BaseLink, { LinkProps } from "next/link"; + +type Props = LinkProps & { + children: ReactNode; + title?: string; + target?: string; + className?: string; + rel?: string; +}; + +const Link = ({ ...props }: Props): JSX.Element => { + if (props.target === "_blank" && props.children) { + props.title = `${props.title || props.children.toString()} - nouvelle fenêtre`; + } + return ; +}; + +export default Link; diff --git a/packages/code-du-travail-frontend/src/modules/common/LogoLink.tsx b/packages/code-du-travail-frontend/src/modules/common/LogoLink.tsx index 8534d9a703..8dde7a7a77 100644 --- a/packages/code-du-travail-frontend/src/modules/common/LogoLink.tsx +++ b/packages/code-du-travail-frontend/src/modules/common/LogoLink.tsx @@ -1,7 +1,7 @@ "use client"; import { fr } from "@codegouvfr/react-dsfr"; import { css } from "@styled-system/css"; -import Link from "next/link"; +import Link from "../common/Link"; export const LogoLink = () => { return ( diff --git a/packages/code-du-travail-frontend/src/modules/config/DefaultLayout.tsx b/packages/code-du-travail-frontend/src/modules/config/DefaultLayout.tsx index 70f9d95ec8..eafafa9a36 100644 --- a/packages/code-du-travail-frontend/src/modules/config/DefaultLayout.tsx +++ b/packages/code-du-travail-frontend/src/modules/config/DefaultLayout.tsx @@ -1,7 +1,7 @@ import { DsfrHead } from "@codegouvfr/react-dsfr/next-appdir/DsfrHead"; import { DsfrProvider } from "@codegouvfr/react-dsfr/next-appdir/DsfrProvider"; import { getHtmlAttributes } from "@codegouvfr/react-dsfr/next-appdir/getHtmlAttributes"; -import Link from "next/link"; +import Link from "../common/Link"; import { MatomoAnalytics } from "./MatomoAnalytics"; import { DefaultColorScheme } from "@codegouvfr/react-dsfr/next-appdir"; import { StartDsfrSystem } from "./StartDsfrSystem"; diff --git a/packages/code-du-travail-frontend/src/modules/config/StartDsfrDark.tsx b/packages/code-du-travail-frontend/src/modules/config/StartDsfrDark.tsx index 50841838b6..4fa83134c1 100644 --- a/packages/code-du-travail-frontend/src/modules/config/StartDsfrDark.tsx +++ b/packages/code-du-travail-frontend/src/modules/config/StartDsfrDark.tsx @@ -1,7 +1,7 @@ "use client"; import { startReactDsfr } from "@codegouvfr/react-dsfr/next-appdir"; -import Link from "next/link"; +import Link from "../common/Link"; declare module "@codegouvfr/react-dsfr/next-appdir" { interface RegisterLink { diff --git a/packages/code-du-travail-frontend/src/modules/config/StartDsfrLight.tsx b/packages/code-du-travail-frontend/src/modules/config/StartDsfrLight.tsx index d9ca61981f..bf4f0a7edb 100644 --- a/packages/code-du-travail-frontend/src/modules/config/StartDsfrLight.tsx +++ b/packages/code-du-travail-frontend/src/modules/config/StartDsfrLight.tsx @@ -1,7 +1,7 @@ "use client"; import { startReactDsfr } from "@codegouvfr/react-dsfr/next-appdir"; -import Link from "next/link"; +import Link from "../common/Link"; declare module "@codegouvfr/react-dsfr/next-appdir" { interface RegisterLink { diff --git a/packages/code-du-travail-frontend/src/modules/config/StartDsfrSystem.tsx b/packages/code-du-travail-frontend/src/modules/config/StartDsfrSystem.tsx index 242e8afc95..973713116e 100644 --- a/packages/code-du-travail-frontend/src/modules/config/StartDsfrSystem.tsx +++ b/packages/code-du-travail-frontend/src/modules/config/StartDsfrSystem.tsx @@ -1,7 +1,7 @@ "use client"; import { startReactDsfr } from "@codegouvfr/react-dsfr/next-appdir"; -import Link from "next/link"; +import Link from "../common/Link"; declare module "@codegouvfr/react-dsfr/next-appdir" { interface RegisterLink { diff --git a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsGlossaire.tsx b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsGlossaire.tsx index 06a9ec4790..8037c4a95b 100644 --- a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsGlossaire.tsx +++ b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsGlossaire.tsx @@ -1,5 +1,5 @@ import { fr } from "@codegouvfr/react-dsfr"; -import Link from "next/link"; +import Link from "../../common/Link"; import { css } from "@styled-system/css"; type Props = { diff --git a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsIntro.tsx b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsIntro.tsx index 1c2da890da..82a537f4e2 100644 --- a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsIntro.tsx +++ b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsIntro.tsx @@ -1,5 +1,5 @@ import { fr } from "@codegouvfr/react-dsfr"; -import Link from "next/link"; +import Link from "../../common/Link"; import { css } from "@styled-system/css"; import Image from "next/image"; import AgreementSearch from "../AgreementSearch.svg"; diff --git a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsSection.tsx b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsSection.tsx index c7bb1ab454..5947d99206 100644 --- a/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsSection.tsx +++ b/packages/code-du-travail-frontend/src/modules/convention-collective/Agreements/AgreementsSection.tsx @@ -1,7 +1,7 @@ import { fr } from "@codegouvfr/react-dsfr"; import { getRouteBySource, SOURCES } from "@socialgouv/cdtn-utils"; import { ListWithArrow } from "../../common/ListWithArrow"; -import Link from "next/link"; +import Link from "../../common/Link"; import { ElasticAgreement } from "@socialgouv/cdtn-types"; type Agreement = Pick; diff --git a/packages/code-du-travail-frontend/src/modules/error/NotFound.tsx b/packages/code-du-travail-frontend/src/modules/error/NotFound.tsx index c407edab2d..d68adc1d63 100644 --- a/packages/code-du-travail-frontend/src/modules/error/NotFound.tsx +++ b/packages/code-du-travail-frontend/src/modules/error/NotFound.tsx @@ -1,7 +1,7 @@ import React from "react"; import { IconError } from "./IconError"; import { fr } from "@codegouvfr/react-dsfr"; -import Link from "next/link"; +import Link from "../common/Link"; export const NotFound: React.FC = () => { return ( diff --git a/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/ContentParser.tsx b/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/ContentParser.tsx index db25ad9084..5bc58d79ee 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/ContentParser.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/ContentParser.tsx @@ -6,6 +6,7 @@ import parse, { } from "html-react-parser"; import { fr } from "@codegouvfr/react-dsfr"; import xss, { escapeAttrValue, getDefaultWhiteList } from "xss"; +import Link from "../common/Link"; const xssWrapper = (text: string): string => { return xss(text, { @@ -18,7 +19,7 @@ const xssWrapper = (text: string): string => { "type", "data-fr-js-collapse-button", ], - div: ["data-src"], + div: ["data-src", "data-title"], }, /* Keep this attribute for all HTML tag. Use it safely. @@ -45,13 +46,14 @@ const options = (): HTMLReactParserOptions => { ) { return (

- Cliquez ici pour voir la vidéo - +

); } diff --git a/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/__tests__/ContentParser.test.tsx b/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/__tests__/ContentParser.test.tsx index d96eb86275..9a380e7801 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/__tests__/ContentParser.test.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-ministere-travail/__tests__/ContentParser.test.tsx @@ -8,7 +8,21 @@ describe("Fiche MT content parser", () => { {contentWithYoutubeVideo} ); - expect(getByText("Cliquez ici pour voir la vidéo")).toBeInTheDocument(); + expect(getByText("Cliquez ici pour voir la vidéo").title).toEqual( + "Cliquez ici pour voir la vidéo Le travail illégal ; la répression | web série droit du travail - nouvelle fenêtre" + ); + expect(getByText("Cliquez ici pour voir la vidéo")).toHaveAttribute( + "href", + "https://www.youtube.com/embed/lSYAHnf9F1Q?t&start=0" + ); + expect(getByText("Cliquez ici pour voir la vidéo")).toHaveAttribute( + "target", + "_blank" + ); + expect(getByText("Cliquez ici pour voir la vidéo")).toHaveAttribute( + "rel", + "noopener noreferrer" + ); }); test("should replace callout with icon by a default one to avoid icon issue", () => { diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/__tests__/__snapshots__/FicheServicePublic.test.tsx.snap b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/__tests__/__snapshots__/FicheServicePublic.test.tsx.snap index cd8b3407a7..0a8d31f6b9 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/__tests__/__snapshots__/FicheServicePublic.test.tsx.snap +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/__tests__/__snapshots__/FicheServicePublic.test.tsx.snap @@ -21,6 +21,7 @@ exports[` should render 1`] = ` href="https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000046771781" rel="noopener noreferrer" target="_blank" + title="loi n°2022-1598 du 21 décembre 2022 - nouvelle fenêtre" > loi n°2022-1598 du 21 décembre 2022 @@ -34,6 +35,7 @@ exports[` should render 1`] = ` href="https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000047455109" rel="noopener noreferrer" target="_blank" + title="n°2023-275 du 17 avril 2023 - nouvelle fenêtre" > n°2023-275 du 17 avril 2023 @@ -290,6 +292,7 @@ exports[` should render 1`] = ` href="https://www.service-public.fr/simulateur/calcul/Demission" rel="noopener noreferrer" target="_blank" + title="Lettre de démission du salarié - nouvelle fenêtre" > Lettre de démission du salarié @@ -580,6 +583,7 @@ exports[` should render 1`] = ` href="https://code.travail.gouv.fr/outils/preavis-demission" rel="noopener noreferrer" target="_blank" + title="Calculer la durée du préavis de démission selon la convention collective - nouvelle fenêtre" > Calculer la durée du préavis de démission selon la convention collective @@ -1234,6 +1238,7 @@ exports[` should render 1`] = ` href="https://www.service-public.fr/simulateur/calcul/Demission" rel="noopener noreferrer" target="_blank" + title="Lettre de démission du salarié - nouvelle fenêtre" > Lettre de démission du salarié @@ -1953,6 +1958,7 @@ exports[` should render 1`] = ` href="https://www.service-public.fr/simulateur/calcul/Demission" rel="noopener noreferrer" target="_blank" + title="Lettre de démission du salarié - nouvelle fenêtre" > Lettre de démission du salarié @@ -2452,6 +2458,7 @@ exports[` should render 1`] = ` href="https://www.service-public.fr/simulateur/calcul/Demission" rel="noopener noreferrer" target="_blank" + title="Lettre de démission du salarié - nouvelle fenêtre" > Lettre de démission du salarié @@ -2462,6 +2469,7 @@ exports[` should render 1`] = ` href="https://code.travail.gouv.fr/outils/preavis-demission" rel="noopener noreferrer" target="_blank" + title="Calculer la durée du préavis de démission selon la convention collective - nouvelle fenêtre" > Calculer la durée du préavis de démission selon la convention collective diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/LienExterne.tsx b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/LienExterne.tsx index 1c9b259d66..b25d68cec5 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/LienExterne.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/LienExterne.tsx @@ -1,11 +1,12 @@ import React from "react"; import { getInChildrenByName, getText } from "../utils"; -import Link from "next/link"; + import { FicheSPDataLienExterne, FicheSPDataLienExterneCommente, } from "../type"; +import Link from "../../../common/Link"; export const LienExterneCommente = ({ data, diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/OuSAdresser.tsx b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/OuSAdresser.tsx index 18aae7ff1d..f14d5a4bcd 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/OuSAdresser.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/OuSAdresser.tsx @@ -4,8 +4,9 @@ import { getInChildrenByName, getTitleInChildren } from "../utils"; import { ElementBuilder } from "./ElementBuilder"; import Title from "./Title"; import { fr } from "@codegouvfr/react-dsfr"; -import Link from "next/link"; + import { FicheSPDataOuSAdresser, FicheSPDataRessourceWeb } from "../type"; +import Link from "../../../common/Link"; export const OuSAdresser = ({ data, diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/ServiceEnLigne.tsx b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/ServiceEnLigne.tsx index 247142ab3b..e87e4c0a34 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/ServiceEnLigne.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/ServiceEnLigne.tsx @@ -1,10 +1,11 @@ import React from "react"; import { getText } from "../utils"; -import Link from "next/link"; + import { fr } from "@codegouvfr/react-dsfr"; import { FicheSPDataServiceEnLigne } from "../type"; import { cleanUrl } from "./LienExterne"; +import Link from "../../../common/Link"; export const ServiceEnLigne = ({ data, diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/Video.tsx b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/Video.tsx index 7cb07b5609..7bc6fa83ab 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/Video.tsx +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/Video.tsx @@ -1,8 +1,8 @@ import React from "react"; import { getText } from "../utils"; -import Link from "next/link"; import { FicheSPDataVideo } from "../type"; +import Link from "../../../common/Link"; export const Video = ({ data }: { data: FicheSPDataVideo }) => { const url = data.attributes.URL; diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Avertissement.test.tsx.snap b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Avertissement.test.tsx.snap index e3838602fc..787ae4369f 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Avertissement.test.tsx.snap +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Avertissement.test.tsx.snap @@ -24,6 +24,7 @@ exports[` affiche un avertissement 1`] = ` href="https://www.legifrance.gouv.fr/loda/id/JORFTEXT000045197395/" rel="noopener noreferrer" target="_blank" + title="loi n°2022-217 du 21 février 2022 - nouvelle fenêtre" > loi n°2022-217 du 21 février 2022 @@ -34,6 +35,7 @@ exports[` affiche un avertissement 1`] = ` href="https://www.legifrance.gouv.fr/jorf/id/JORFTEXT000046780040" rel="noopener noreferrer" target="_blank" + title="L'ordonnance n°2022-1067 du 22 décembre 2022 - nouvelle fenêtre" > L'ordonnance n°2022-1067 du 22 décembre 2022 diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/LienExterne.test.tsx.snap b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/LienExterne.test.tsx.snap index 933f06631c..3ff9e0de17 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/LienExterne.test.tsx.snap +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/LienExterne.test.tsx.snap @@ -6,6 +6,7 @@ exports[` should render 1`] = ` href="https://formulaire.defenseurdesdroits.fr/code/afficher.php?ETAPE=accueil_2016" rel="noopener noreferrer" target="_blank" + title="formulaire de contact - nouvelle fenêtre" > formulaire de contact @@ -22,6 +23,7 @@ exports[` should render 1`] = ` href="http://travail-emploi.gouv.fr/droit-du-travail/contrats-et-carriere/contrats-de-travail/types-de-contrats/article/le-contrat-a-duree-determinee-cdd" rel="noopener noreferrer" target="_blank" + title="Fiche pratique sur le CDD - nouvelle fenêtre" > Fiche pratique sur le CDD diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/OuSAdresser.test.tsx.snap b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/OuSAdresser.test.tsx.snap index 3b3bf1b851..d93aa92aac 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/OuSAdresser.test.tsx.snap +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/OuSAdresser.test.tsx.snap @@ -118,6 +118,7 @@ exports[` should render a ressource web component 1`] = ` href="mailto:contact@fiva.fr" rel="noopener noreferrer" target="_blank" + title="contact@fiva.fr - nouvelle fenêtre" > contact@fiva.fr diff --git a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Video.test.tsx.snap b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Video.test.tsx.snap index 766b0e4784..cc90327707 100644 --- a/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Video.test.tsx.snap +++ b/packages/code-du-travail-frontend/src/modules/fiche-service-public/builder/components/__tests__/__snapshots__/Video.test.tsx.snap @@ -6,6 +6,7 @@ exports[`