Skip to content

Commit

Permalink
feat: add i18n support for ProductTour Checkpoint sr-only message (#2758
Browse files Browse the repository at this point in the history
)

* feat: add i18n support for sr-only message

* fix: add fixes after review

---------

Co-authored-by: Kyrylo Hudym-Levkovych <kyr.hudym@kyrs-MacBook-Pro.local>
  • Loading branch information
khudym and Kyrylo Hudym-Levkovych authored Nov 1, 2023
1 parent 3b7bbd5 commit f124792
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 189 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"example:start:with-theme": "npm run start:with-theme --workspace=example",
"generate-changelog": "node generate-changelog.js",
"i18n_compile": "formatjs compile-folder --format transifex ./src/i18n/messages ./src/i18n/messages",
"i18n_extract": "formatjs extract 'src/**/*.{jsx,js,tsx,ts}' --out-file ./src/i18n/transifex_input.json --format transifex",
"i18n_extract": "formatjs extract 'src/**/*.{jsx,js,tsx,ts}' --out-file ./src/i18n/transifex_input.json --ignore='**/*.d.ts' --format transifex",
"type-check": "tsc --noEmit && tsc --project www --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"build-types": "tsc --emitDeclarationOnly",
Expand Down
11 changes: 9 additions & 2 deletions src/ProductTour/Checkpoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { useMediaQuery } from 'react-responsive';
import PropTypes from 'prop-types';
import { createPopper } from '@popperjs/core';
import { FormattedMessage } from 'react-intl';

import breakpoints from '../utils/breakpoints';

Expand Down Expand Up @@ -95,8 +96,14 @@ const Checkpoint = React.forwardRef(({
role="dialog"
style={{ visibility: checkpointVisible ? 'visible' : 'hidden', pointerEvents: checkpointVisible ? 'auto' : 'none' }}
>
{/* This text is not translated due to Paragon's lack of i18n support */}
<span className="sr-only">Top of step {index + 1}</span>
<span className="sr-only">
<FormattedMessage
id="pgn.ProductTour.Checkpoint.position-text"
defaultMessage="Top of step {step}"
value={{ step: index + 1 }}
description="Screen-reader message to indicate the user's position in a sequence of checkpoints."
/>
</span>
{(title || !isOnlyCheckpoint) && (
<div className="pgn__checkpoint-header">
<CheckpointTitle>{title}</CheckpointTitle>
Expand Down
17 changes: 9 additions & 8 deletions src/ProductTour/Checkpoint.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { IntlProvider } from 'react-intl';

import * as popper from '@popperjs/core';

Expand All @@ -24,7 +25,7 @@ describe('Checkpoint', () => {
describe('second Checkpoint in Tour', () => {
beforeEach(() => {
render(
<>
<IntlProvider locale="en" messages={{}}>
<div id="target-element">...</div>
<Checkpoint
advanceButtonText="Next"
Expand All @@ -39,7 +40,7 @@ describe('Checkpoint', () => {
title="Checkpoint title"
totalCheckpoints={5}
/>
</>,
</IntlProvider>,
);
});

Expand Down Expand Up @@ -75,7 +76,7 @@ describe('Checkpoint', () => {
describe('last Checkpoint in Tour', () => {
beforeEach(() => {
render(
<>
<IntlProvider locale="en" messages={{}}>
<div id="#last-element" />
<Checkpoint
advanceButtonText="Next"
Expand All @@ -90,7 +91,7 @@ describe('Checkpoint', () => {
title="Checkpoint title"
totalCheckpoints={5}
/>
</>,
</IntlProvider>,
);
});

Expand All @@ -108,7 +109,7 @@ describe('Checkpoint', () => {
describe('only one Checkpoint in Tour', () => {
beforeEach(() => {
render(
<>
<IntlProvider locale="en" messages={{}}>
<div id="#target-element" />
<Checkpoint
advanceButtonText="Next"
Expand All @@ -123,7 +124,7 @@ describe('Checkpoint', () => {
title="Checkpoint title"
totalCheckpoints={1}
/>
</>,
</IntlProvider>,
);
});

Expand All @@ -140,7 +141,7 @@ describe('Checkpoint', () => {
describe('only one Checkpoint in Tour and showDismissButton set to true', () => {
it('it renders dismiss button and end button', () => {
render(
<>
<IntlProvider locale="en" messages={{}}>
<div id="#target-element" />
<Checkpoint
advanceButtonText="Next"
Expand All @@ -156,7 +157,7 @@ describe('Checkpoint', () => {
totalCheckpoints={1}
showDismissButton
/>
</>,
</IntlProvider>,
);
expect(screen.getByText('Dismiss', { selector: 'button' })).toBeInTheDocument();
expect(screen.getByText('End', { selector: 'button' })).toBeInTheDocument();
Expand Down
Loading

0 comments on commit f124792

Please sign in to comment.