Skip to content

Commit

Permalink
fix: fix spaces in status aria-labels (#1111)
Browse files Browse the repository at this point in the history
fixes #1108
  • Loading branch information
nolanlawson authored Mar 21, 2019
1 parent f69c5c6 commit c896836
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/routes/_components/status/Status.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@
import { getAccountAccessibleName } from '../../_a11y/getAccountAccessibleName'
import { getAccessibleLabelForStatus } from '../../_a11y/getAccessibleLabelForStatus'
import { formatTimeagoDate } from '../../_intl/formatTimeagoDate'
import { htmlToPlainText } from '../../_utils/htmlToPlainText'
import { measureText } from '../../_utils/measureText'
import { LONG_POST_LENGTH, LONG_POST_TEXT } from '../../_static/statuses'
import { absoluteDateFormatter } from '../../_utils/formatters'
import { composeNewStatusMentioning } from '../../_actions/mention'
import { applyFocusStylesToParent } from '../../_utils/events'
import noop from 'lodash-es/noop'
import { createStatusOrNotificationUuid } from '../../_utils/createStatusOrNotificationUuid'
import { statusHtmlToPlainText } from '../../_utils/statusHtmlToPlainText'

const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea'])
const isUserInputElement = node => INPUT_TAGS.has(node.localName)
Expand Down Expand Up @@ -231,7 +231,8 @@
originalAccountId: ({ originalAccount }) => originalAccount.id,
accountForShortcut: ({ originalAccount, notification }) => notification ? notification.account : originalAccount,
visibility: ({ originalStatus }) => originalStatus.visibility,
plainTextContent: ({ content }) => htmlToPlainText(content),
mentions: ({ originalStatus }) => originalStatus.mentions || [],
plainTextContent: ({ content, mentions }) => statusHtmlToPlainText(content, mentions),
plainTextContentLength: ({ plainTextContent }) => measureText(plainTextContent),
plainTextContentOverLength: ({ plainTextContentLength }) => plainTextContentLength > LONG_POST_LENGTH,
spoilerText: ({ originalStatus, plainTextContentOverLength }) => (
Expand Down
13 changes: 0 additions & 13 deletions src/routes/_utils/htmlToPlainText.js

This file was deleted.

14 changes: 9 additions & 5 deletions src/routes/_utils/statusHtmlToPlainText.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ function massageMentions (doc, mentions) {
// paragraphs should be separated by double newlines
// single <br/>s should become single newlines
function innerTextRetainingNewlines (doc) {
let res = ''
let paragraphs = doc.querySelectorAll('p')
return Array.from(paragraphs).map(paragraph => {
for (let i = 0; i < paragraphs.length; i++) {
let paragraph = paragraphs[i]
let brs = paragraph.querySelectorAll('br')
Array.from(brs).forEach(br => {
for (let j = 0; j < brs.length; j++) {
let br = brs[j]
br.parentNode.replaceChild(doc.createTextNode('\n'), br)
})
return paragraph.textContent
}).join('\n\n')
}
res += (i > 0 ? '\n\n' : '') + paragraph.textContent
}
return res
}

export function statusHtmlToPlainText (html, mentions) {
Expand Down
18 changes: 17 additions & 1 deletion tests/spec/120-status-aria-label.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loginAsFoobar } from '../roles'
import { getNthStatus } from '../utils'
import { postEmptyStatusWithMediaAs } from '../serverActions'
import { postAs, postEmptyStatusWithMediaAs } from '../serverActions'

fixture`120-status-aria-label.js`
.page`http://localhost:4002`
Expand All @@ -14,3 +14,19 @@ test('aria-labels for statuses with no content text', async t => {
/foobar, (.+ ago|just now), @foobar, Public/i
)
})

test('aria-labels with links', async t => {
let content = 'Text here\n\nMore text\n\n' +
'https://example.com/long/url/here/very/long/yes/so/long\n\n' +
'#woot #yolo'

let expected = 'admin, Text here More text ' +
'https://example.com/long/url/here/very/long/yes/so/long #woot #yolo,'

await postAs('admin', content)

await loginAsFoobar(t)
await t
.hover(getNthStatus(1))
.expect(getNthStatus(1).getAttribute('aria-label')).contains(expected)
})

0 comments on commit c896836

Please sign in to comment.