From 5052ecd399d206541f56501aa7b1b3226fc44ea1 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 9 Mar 2019 13:03:00 -0800 Subject: [PATCH 1/5] fix: improve search/clear a11y fixes #221 --- README.md | 1 + css/emoji-mart.css | 21 ++++++++++++++--- src/components/picker/nimble-picker.js | 1 + src/components/search.js | 31 +++++++++++++++++++++----- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 30cbec0..fc13c58 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ import { Picker } from 'emoji-mart' #### I18n ```js search: 'Search', +clear: 'Clear', // Accessible label on "clear" button notfound: 'No Emoji Found', skintext: 'Choose your default skin tone', categories: { diff --git a/css/emoji-mart.css b/css/emoji-mart.css index 12daf72..d4ddbeb 100644 --- a/css/emoji-mart.css +++ b/css/emoji-mart.css @@ -100,14 +100,15 @@ border-radius: 5px; border: 1px solid #d9d9d9; outline: 0; + -webkit-appearance: none; } .emoji-mart-search-icon { position: absolute; - top: 9px; - right: 16px; + top: 7px; + right: 11px; z-index: 2; - padding: 0; + padding: 2px 5px 1px; border: none; background: none; } @@ -369,3 +370,17 @@ .emoji-mart-skin-tone-4 { background-color: #bf8f68 } .emoji-mart-skin-tone-5 { background-color: #9b643d } .emoji-mart-skin-tone-6 { background-color: #594539 } + +/* For screenreaders only, via https://stackoverflow.com/a/19758620 */ +.emoji-mart-sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + border: 0; +} + + diff --git a/src/components/picker/nimble-picker.js b/src/components/picker/nimble-picker.js index 1b8c120..bcbf100 100644 --- a/src/components/picker/nimble-picker.js +++ b/src/components/picker/nimble-picker.js @@ -18,6 +18,7 @@ import { PickerDefaultProps } from '../../utils/shared-default-props' const I18N = { search: 'Search', + clear: 'Clear', // Accessible label on "clear" button notfound: 'No Emoji Found', skintext: 'Choose your default skin tone', categories: { diff --git a/src/components/search.js b/src/components/search.js index 19992dd..871aeda 100644 --- a/src/components/search.js +++ b/src/components/search.js @@ -4,12 +4,15 @@ import PropTypes from 'prop-types' import { search as icons } from '../svgs' import NimbleEmojiIndex from '../utils/emoji-index/nimble-emoji-index' +let id = 0 + export default class Search extends React.PureComponent { constructor(props) { super(props) this.state = { icon: icons.search, isSearching: false, + id: ++id } this.data = props.data @@ -59,28 +62,46 @@ export default class Search extends React.PureComponent { } } + clearIfNotSearching () { + const { isSearching } = this.state + if (!isSearching) { + this.clear() + } + } + setRef(c) { this.input = c } render() { - var { i18n, autoFocus } = this.props - var { icon, isSearching } = this.state + const { i18n, autoFocus } = this.props + const { icon, id } = this.state + + let inputId = `emoji-mart-search-${id}` return (
+ {/* + * Use a