From 6235af4592c52a657415ffae772bd83ec106bc13 Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 21 Jan 2023 01:07:07 -0500 Subject: Make screenreaders read out autocomplete results --- src/components/emoji_input/emoji_input.js | 53 ++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'src/components/emoji_input/emoji_input.js') diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index ba5f7552..020e9fde 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -1,6 +1,7 @@ import Completion from '../../services/completion/completion.js' import EmojiPicker from '../emoji_picker/emoji_picker.vue' import Popover from 'src/components/popover/popover.vue' +import ScreenReaderNotice from 'src/components/screen_reader_notice/screen_reader_notice.vue' import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue' import { take } from 'lodash' import { findOffset } from '../../services/offset_finder/offset_finder.service.js' @@ -109,9 +110,10 @@ const EmojiInput = { }, data () { return { + randomSeed: `${Math.random()}`.replace('.', '-'), input: undefined, caretEl: undefined, - highlighted: 0, + highlighted: -1, caret: 0, focused: false, blurTimeout: null, @@ -125,7 +127,8 @@ const EmojiInput = { components: { Popover, EmojiPicker, - UnicodeDomainIndicator + UnicodeDomainIndicator, + ScreenReaderNotice }, computed: { padEmoji () { @@ -203,6 +206,12 @@ const EmojiInput = { top: this.input.scrollTop, left: this.input.scrollLeft }) + }, + suggestionListId () { + return `suggestions-${this.randomSeed}` + }, + suggestionItemId () { + return (index) => `suggestion-item-${index}-${this.randomSeed}` } }, mounted () { @@ -278,6 +287,10 @@ const EmojiInput = { ...rest, img: imageUrl || '' })) + this.$refs.screenReaderNotice.announce( + this.$tc('tool_tip.autocomplete_available', + this.suggestions.length, + { number: this.suggestions.length })) } }, methods: { @@ -374,27 +387,24 @@ const EmojiInput = { }, cycleBackward (e) { const len = this.suggestions.length || 0 - if (len > 1) { - this.highlighted -= 1 - if (this.highlighted < 0) { - this.highlighted = this.suggestions.length - 1 - } - e.preventDefault() - } else { - this.highlighted = 0 + + this.highlighted -= 1 + if (this.highlighted === -1) { + this.input.focus() + } else if (this.highlighted < -1) { + this.highlighted = len - 1 } + e.preventDefault() }, cycleForward (e) { const len = this.suggestions.length || 0 - if (len > 1) { - this.highlighted += 1 - if (this.highlighted >= len) { - this.highlighted = 0 - } - e.preventDefault() - } else { - this.highlighted = 0 + + this.highlighted += 1 + if (this.highlighted >= len) { + this.highlighted = -1 + this.input.focus() } + e.preventDefault() }, scrollIntoView () { const rootRef = this.$refs.picker.$el @@ -540,6 +550,13 @@ const EmojiInput = { }) }, resize () { + }, + autoCompleteItemLabel (suggestion) { + if (suggestion.user) { + return suggestion.displayText + ' ' + suggestion.detailText + } else { + return this.maybeLocalizedEmojiName(suggestion) + } } } } -- cgit v1.2.3-70-g09d2 From 72cb9e8bdbd41b66f72f8dd0dcd52cc04c7a2245 Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 21 Jan 2023 01:28:43 -0500 Subject: Make all emoji inputs screen-reader-friendly --- src/components/emoji_input/emoji_input.js | 1 + .../post_status_form/post_status_form.js | 4 ++ .../post_status_form/post_status_form.vue | 25 ++++++------ src/components/settings_modal/tabs/profile_tab.js | 4 ++ src/components/settings_modal/tabs/profile_tab.vue | 46 ++++++++++++++-------- .../attributes_helper/attributes_helper.service.js | 8 ++++ 6 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 src/services/attributes_helper/attributes_helper.service.js (limited to 'src/components/emoji_input/emoji_input.js') diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js index 020e9fde..3b0db786 100644 --- a/src/components/emoji_input/emoji_input.js +++ b/src/components/emoji_input/emoji_input.js @@ -287,6 +287,7 @@ const EmojiInput = { ...rest, img: imageUrl || '' })) + this.highlighted = -1 this.$refs.screenReaderNotice.announce( this.$tc('tool_tip.autocomplete_available', this.suggestions.length, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index eb55cfcc..b75fee69 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -8,6 +8,7 @@ import Gallery from 'src/components/gallery/gallery.vue' import StatusContent from '../status_content/status_content.vue' import fileTypeService from '../../services/file_type/file_type.service.js' import { findOffset } from '../../services/offset_finder/offset_finder.service.js' +import { propsToNative } from '../../services/attributes_helper/attributes_helper.service.js' import { reject, map, uniqBy, debounce } from 'lodash' import suggestor from '../emoji_input/suggestor.js' import { mapGetters, mapState } from 'vuex' @@ -629,6 +630,9 @@ const PostStatusForm = { }, openProfileTab () { this.$store.dispatch('openSettingsModalTab', 'profile') + }, + propsToNative (props) { + return propsToNative(props) } } } diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index 26a5acc4..328e145f 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -124,14 +124,17 @@ :suggest="emojiSuggestor" class="form-control" > - + - +

{{ $t('settings.bio') }}

-