make default alt text 'image description' (#15063)
This commit is contained in:
parent
b900c8de92
commit
7a9352ba86
7 changed files with 25 additions and 21 deletions
|
|
@ -3,7 +3,9 @@ import PropTypes from 'prop-types';
|
|||
import { Button } from '@crayons';
|
||||
|
||||
function linksToMarkdownForm(imageLinks) {
|
||||
return imageLinks.map((imageLink) => ``).join('\n');
|
||||
return imageLinks
|
||||
.map((imageLink) => ``)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
const CopyIcon = () => (
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ function handleImageSuccess(textAreaRef) {
|
|||
// Function is within the component to be able to access
|
||||
// textarea ref.
|
||||
const editableBodyElement = textAreaRef.current;
|
||||
const { links, image } = response;
|
||||
const altText = image[0]
|
||||
? image[0].name.replace(/\.[^.]+$/, '')
|
||||
: 'alt text';
|
||||
const markdownImageLink = `\n`;
|
||||
const { links } = response;
|
||||
|
||||
const markdownImageLink = `\n`;
|
||||
const { selectionStart, selectionEnd, value } = editableBodyElement;
|
||||
const before = value.substring(0, selectionStart);
|
||||
const after = value.substring(selectionEnd, value.length);
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ export const noDefaultAltTextRule = {
|
|||
children.forEach((contentChild) => {
|
||||
if (
|
||||
contentChild.type === 'image' &&
|
||||
contentChild.line.toLowerCase().includes('![alt text]')
|
||||
contentChild.line.toLowerCase().includes('![image description]')
|
||||
) {
|
||||
onError({
|
||||
lineNumber: contentChild.lineNumber,
|
||||
detail: '/p/editor_guide#alt-text-for-images',
|
||||
context: `Consider replacing the 'alt text' in square brackets at ${getImageTextString(
|
||||
context: `Consider replacing the 'Image description' in square brackets at ${getImageTextString(
|
||||
contentChild.line,
|
||||
)} with a description of the image`,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
When adding GIFs to posts and comments, please note that there is a limit of 200 megapixels per frame/page.
|
||||
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsLaFSo9--/c_fill,f_auto,fl_progressive,h_220,q_auto,w_220/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg" alt="example image, with sloan" loading="lazy" />
|
||||
</p>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<figure>
|
||||
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsLaFSo9--/c_fill,f_auto,fl_progressive,h_50,q_auto,w_50/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg" alt="example image, with sloan" loading="lazy" />
|
||||
<figcaption>You can even add a caption using the HTML <code>figcaption</code> tag!</figcaption>
|
||||
|
|
@ -97,8 +97,8 @@
|
|||
<%= render partial: "editor_guide_h3", locals: { id: "alt-text-for-images", title: "Providing alternative descriptions for images" } %>
|
||||
<p>Some users might not be able to see or easily process images that you use in your posts. Providing an alternative description for an image helps make sure that everyone can understand your post, whether they can see the image or not.</p>
|
||||
<p>When you upload an image in the editor, you will see the following text to copy and paste into your post:</p>
|
||||
<pre></pre>
|
||||
<p>Replace the "Alt Text" in square brackets with a description of your image - for example:</p>
|
||||
<pre></pre>
|
||||
<p>Replace the "Image description" in square brackets with a description of your image - for example:</p>
|
||||
<pre></pre>
|
||||
<p>By doing this, if someone reads your post using an assistive device like a screen reader (which turns written content into spoken audio) they will hear the description you entered.</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
When adding GIFs to posts and comments, please note that there is a limit of 200 megapixels per frame/page.
|
||||
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsLaFSo9--/c_fill,f_auto,fl_progressive,h_220,q_auto,w_220/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg" alt="example image, with sloan" loading="lazy" />
|
||||
</p>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<figcaption> You can even add a caption using the HTML <code>figcaption</code> tag!</figcaption>
|
||||
|
||||
<h3>Headers</h3>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<h3><strong>Inline Images</strong></h3>
|
||||
<p>
|
||||
<img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OsLaFSo9--/c_fill,f_auto,fl_progressive,h_220,q_auto,w_220/https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg" alt="example image, with sloan" loading="lazy" />
|
||||
<code></code>
|
||||
<code></code>
|
||||
</p>
|
||||
|
||||
<h3><strong>Headers</strong></h3>
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ describe('Post Editor', () => {
|
|||
|
||||
it('should show a maximum of 3 accessibility suggestions', () => {
|
||||
const postTextWithFourErrors =
|
||||
'# Heading level 1\n\n\n#### Heading level 4';
|
||||
'# Heading level 1\n\n\n#### Heading level 4';
|
||||
cy.findByRole('form', { name: /^Edit post$/i }).as('articleForm');
|
||||
|
||||
cy.get('@articleForm')
|
||||
|
|
@ -239,7 +239,7 @@ describe('Post Editor', () => {
|
|||
|
||||
// Check each expected description has appeared
|
||||
cy.findByText(
|
||||
"Consider replacing the 'alt text' in square brackets at  with a description of the image",
|
||||
"Consider replacing the 'Image description' in square brackets at  with a description of the image",
|
||||
);
|
||||
cy.findByText(
|
||||
'Consider adding an image description in the square brackets at ',
|
||||
|
|
@ -259,7 +259,7 @@ describe('Post Editor', () => {
|
|||
|
||||
it('should display image suggestions over heading suggestions', () => {
|
||||
const textWithThreeImageErrors =
|
||||
'\n\n';
|
||||
'\n\n';
|
||||
const textWithHeadingErrors = '# Heading level 1\n #### Heading level 4';
|
||||
|
||||
cy.findByRole('form', { name: /^Edit post$/i }).as('articleForm');
|
||||
|
|
@ -351,18 +351,20 @@ describe('Post Editor', () => {
|
|||
cy.get('@articleForm')
|
||||
.findByLabelText('Post Content')
|
||||
.clear()
|
||||
.type('\n');
|
||||
.type(
|
||||
'\n',
|
||||
);
|
||||
|
||||
cy.get('@articleForm')
|
||||
.findByRole('button', { name: /^Preview$/i })
|
||||
.click();
|
||||
|
||||
cy.findByText(
|
||||
"Consider replacing the 'alt text' in square brackets at  with a description of the image",
|
||||
"Consider replacing the 'Image description' in square brackets at  with a description of the image",
|
||||
);
|
||||
|
||||
cy.findByText(
|
||||
"Consider replacing the 'alt text' in square brackets at  with a description of the image",
|
||||
"Consider replacing the 'Image description' in square brackets at  with a description of the image",
|
||||
);
|
||||
|
||||
cy.findAllByRole('link', {
|
||||
|
|
@ -381,14 +383,16 @@ describe('Post Editor', () => {
|
|||
cy.get('@articleForm')
|
||||
.findByLabelText('Post Content')
|
||||
.clear()
|
||||
.type('Some text  Some more text');
|
||||
.type(
|
||||
'Some text  Some more text',
|
||||
);
|
||||
|
||||
cy.get('@articleForm')
|
||||
.findByRole('button', { name: /^Preview$/i })
|
||||
.click();
|
||||
|
||||
cy.findByText(
|
||||
"Consider replacing the 'alt text' in square brackets at  with a description of the image",
|
||||
"Consider replacing the 'Image description' in square brackets at  with a description of the image",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue