Add more descriptive accessible names for save/bookmark-buttons (#18583)

This commit is contained in:
Eevis Panula 2022-11-10 16:48:13 +02:00 committed by GitHub
parent e81dc39f13
commit 09e327b7c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 23 deletions

View file

@ -285,7 +285,7 @@ function buildArticleHTML(article, currentUserId = null) {
class="c-btn c-btn--icon-alone bookmark-button"
data-reactable-id="${article.id}"
data-article-author-id="${article.user_id}"
aria-label="Save to reading list">
aria-label="Save post ${article.title} to reading list">
<span class="bm-initial">${saveSVG}</span>
<span class="bm-success">${saveFilledSVG}</span>
</button>

View file

@ -243,13 +243,13 @@ Object {
1 min read
</small>
<button
aria-label="Save to reading list"
aria-label="Save post Unbranded Home Loan Account to reading list"
aria-pressed="false"
class="c-btn c-btn--icon-alone"
data-initial-feed="true"
data-reactable-id="62407"
id="article-save-button-62407"
title="Save to reading list"
title="Save post Unbranded Home Loan Account to reading list"
type="button"
>
<svg
@ -512,13 +512,13 @@ Object {
1 min read
</small>
<button
aria-label="Save to reading list"
aria-label="Save post Unbranded Home Loan Account to reading list"
aria-pressed="false"
class="c-btn c-btn--icon-alone"
data-initial-feed="true"
data-reactable-id="62407"
id="article-save-button-62407"
title="Save to reading list"
title="Save post Unbranded Home Loan Account to reading list"
type="button"
>
<svg

View file

@ -24,8 +24,8 @@ export const SaveButton = ({
<Button
id={`article-save-button-${article.id}`}
variant="default"
title="Save to reading list"
aria-label="Save to reading list"
title={`Save post ${article.title} to reading list`}
aria-label={`Save post ${article.title} to reading list`}
aria-pressed={isBookmarked}
icon={isBookmarked ? BookmarkFilledSVG : BookmarkSVG}
data-initial-feed

View file

@ -22,10 +22,10 @@ it('should have no a11y violations', async () => {
});
it('should render button as bookmarked', () => {
const article = { class_name: 'Article', id: 1 };
const article = { class_name: 'Article', id: 1, title: 'Article' };
const { queryByRole } = render(<SaveButton article={article} isBookmarked />);
const saveButton = queryByRole('button', {
name: 'Save to reading list',
name: `Save post ${article.title} to reading list`,
pressed: true,
});
@ -33,12 +33,12 @@ it('should render button as bookmarked', () => {
});
it('should button as not being bookmarked', () => {
const article = { class_name: 'Article', id: 1 };
const article = { class_name: 'Article', id: 1, title: 'Article' };
const { queryByRole } = render(
<SaveButton article={article} isBookmarked={false} />,
);
const saveButton = queryByRole('button', {
name: 'Save to reading list',
name: `Save post ${article.title} to reading list`,
pressed: false,
});
@ -46,15 +46,17 @@ it('should button as not being bookmarked', () => {
});
it('should bookmark when it previously was not', async () => {
const article = { class_name: 'Article', id: 1 };
const article = { class_name: 'Article', id: 1, title: 'Article' };
const { getByRole, findByRole } = render(
<SaveButton onClick={jest.fn()} article={article} isBookmarked={false} />,
);
const saveButton = getByRole('button', { name: 'Save to reading list' });
const saveButton = getByRole('button', {
name: `Save post ${article.title} to reading list`,
});
saveButton.click();
const savedButton = await findByRole('button', {
name: 'Save to reading list',
name: `Save post ${article.title} to reading list`,
pressed: true,
});
@ -62,19 +64,19 @@ it('should bookmark when it previously was not', async () => {
});
it('should unbookmark when it previously was bookmarked', async () => {
const article = { class_name: 'Article', id: 1 };
const article = { class_name: 'Article', id: 1, title: 'Article' };
const { getByRole, findByRole } = render(
<SaveButton onClick={jest.fn()} article={article} isBookmarked />,
);
const savedButton = getByRole('button', {
name: 'Save to reading list',
name: `Save post ${article.title} to reading list`,
pressed: true,
});
savedButton.click();
const saveButton = await findByRole('button', {
name: 'Save to reading list',
name: `Save post ${article.title} to reading list`,
pressed: false,
});

View file

@ -153,8 +153,8 @@
class="c-btn c-btn--icon-alone bookmark-button"
data-reactable-id="<%= story.id %>"
data-article-author-id="<%= story.user_id %>"
aria-label="<%= t("views.articles.save.aria_label") %>"
title="<%= t("views.articles.save.title") %>">
aria-label="<%= t("views.articles.save.aria_label", title: story.title) %>"
title="<%= t("views.articles.save.title", title: story.title) %>">
<span class="bm-initial">
<%= inline_svg_tag("small-save.svg", alt: "", aria_hidden: true) %>
</span>

View file

@ -62,8 +62,8 @@ en:
one: '#discuss <img src="%{image}" />%{count}'
other: '#discuss <img src="%{image}" />%{count}'
save:
title: Save to reading list
aria_label: Save to reading list
title: "Save post %{title} to reading list"
aria_label: "Save post %{title} to reading list"
initial: Save
success: Saved
scheduled:

View file

@ -59,8 +59,8 @@ fr:
one: '#discuss <img src="%{image}" />%{count}'
other: '#discuss <img src="%{image}" />%{count}'
save:
title: Save to reading list
aria_label: Save to reading list
title: "Save post %{title} to reading list"
aria_label: "Save post %{title} to reading list"
initial: Save
success: Saved
series: