Pinafore-Web-Client-Frontend/src/routes/_utils/createAutosuggestAccessible...

21 lines
744 B
JavaScript
Raw Normal View History

import { removeEmoji } from './removeEmoji'
export function createAutosuggestAccessibleLabel (
autosuggestType, $omitEmojiInDisplayNames,
selectedIndex, searchResults) {
2019-08-03 22:49:37 +02:00
const selected = searchResults[selectedIndex]
let label
if (autosuggestType === 'emoji') {
label = `${selected.shortcode}`
} else { // account
let displayName = selected.display_name || selected.username
2019-08-03 22:49:37 +02:00
const emojis = selected.emojis || []
displayName = $omitEmojiInDisplayNames
? removeEmoji(displayName, emojis) || displayName
: displayName
label = `${displayName} @${selected.acct}`
}
return `${label} (${selectedIndex + 1} of ${searchResults.length}). ` +
`Press up and down arrows to review and enter to select.`
}