Skip to content

Commit

Permalink
fix: put annotation in title/aria-label (#369)
Browse files Browse the repository at this point in the history
Fixes #366
  • Loading branch information
nolanlawson committed Oct 8, 2023
1 parent 0524c1d commit bd2004b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/bundlesize.js
Expand Up @@ -5,7 +5,7 @@ import { promisify } from 'node:util'
import prettyBytes from 'pretty-bytes'
import fs from 'node:fs/promises'

const MAX_SIZE_MIN = '42.6 kB'
const MAX_SIZE_MIN = '42.7 kB'
const MAX_SIZE_MINGZ = '15 kB'

const FILENAME = './bundle.js'
Expand Down
4 changes: 2 additions & 2 deletions src/picker/components/Picker/Picker.html
Expand Up @@ -154,7 +154,7 @@
<button role={searchMode ? 'option' : 'menuitem'}
aria-selected={searchMode ? i == activeSearchItem : ''}
aria-label={labelWithSkin(emoji, currentSkinTone)}
title={emoji.title}
title={titleForEmoji(emoji)}
class="emoji {searchMode && i === activeSearchItem ? 'active' : ''}"
id="emo-{emoji.id}">
{#if emoji.unicode}
Expand All @@ -181,7 +181,7 @@
{#each currentFavorites as emoji, i (emoji.id)}
<button role="menuitem"
aria-label={labelWithSkin(emoji, currentSkinTone)}
title={emoji.title}
title={titleForEmoji(emoji)}
class="emoji"
id="fav-{emoji.id}">
{#if emoji.unicode}
Expand Down
14 changes: 13 additions & 1 deletion src/picker/components/Picker/Picker.js
Expand Up @@ -62,6 +62,9 @@ let currentGroup
let databaseLoaded = false // eslint-disable-line no-unused-vars
let activeSearchItemId // eslint-disable-line no-unused-vars

// constants
const EMPTY_ARRAY = []

//
// Utils/helpers
//
Expand All @@ -86,7 +89,16 @@ const unicodeWithSkin = (emoji, currentSkinTone) => (

// eslint-disable-next-line no-unused-vars
const labelWithSkin = (emoji, currentSkinTone) => (
uniq([(emoji.name || unicodeWithSkin(emoji, currentSkinTone)), ...(emoji.shortcodes || [])]).join(', ')
uniq([
(emoji.name || unicodeWithSkin(emoji, currentSkinTone)),
emoji.annotation,
...(emoji.shortcodes || EMPTY_ARRAY)
].filter(Boolean)).join(', ')
)

// eslint-disable-next-line no-unused-vars
const titleForEmoji = (emoji) => (
emoji.annotation || (emoji.shortcodes || EMPTY_ARRAY).join(', ')
)

//
Expand Down
6 changes: 3 additions & 3 deletions src/picker/utils/summarizeEmojisForUI.js
Expand Up @@ -15,14 +15,14 @@ export function summarizeEmojisForUI (emojis, emojiSupportLevel) {
return res
}

return emojis.map(({ unicode, skins, shortcodes, url, name, category }) => ({
return emojis.map(({ unicode, skins, shortcodes, url, name, category, annotation }) => ({
unicode,
name,
shortcodes,
url,
category,
annotation,
id: unicode || name,
skins: skins && toSimpleSkinsMap(skins),
title: (shortcodes || []).join(', ')
skins: skins && toSimpleSkinsMap(skins)
}))
}
3 changes: 3 additions & 0 deletions test/spec/picker/custom.test.js
Expand Up @@ -79,6 +79,9 @@ describe('Custom emojis tests', () => {

await waitFor(() => expect(getByRole(container, 'menuitem', { name: 'themonkey' })).toBeVisible())

expect(getByRole(container, 'menuitem', { name: 'themonkey' }).getAttribute('title')).toStrictEqual('themonkey')
expect(getByRole(container, 'menuitem', { name: 'themonkey' }).getAttribute('aria-label')).toStrictEqual('themonkey')

getByRole(container, 'tab', { name: 'Flags' }).click()

await waitFor(() => expect(getByRole(container, 'menuitem', { name: /🏁/ })).toBeVisible())
Expand Down
8 changes: 4 additions & 4 deletions test/spec/picker/dataSource.test.js
Expand Up @@ -34,8 +34,8 @@ describe('dataSource test', () => {
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ })).toBeVisible())

// no shortcodes, no title
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('title')).toStrictEqual('')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('aria-label')).toStrictEqual('πŸ˜€')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('title')).toStrictEqual('grinning face')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('aria-label')).toStrictEqual('πŸ˜€, grinning face')

await picker.database.delete()
await tick(20)
Expand All @@ -54,8 +54,8 @@ describe('dataSource test', () => {
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ })).toBeVisible())

// no shortcodes, no title
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('title')).toStrictEqual('gleeful')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('aria-label')).toStrictEqual('πŸ˜€, gleeful')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('title')).toStrictEqual('grinning face')
expect(getByRole(container, 'menuitem', { name: /πŸ˜€/ }).getAttribute('aria-label')).toStrictEqual('πŸ˜€, grinning face, gleeful')

await picker.database.delete()
await tick(20)
Expand Down

0 comments on commit bd2004b

Please sign in to comment.