Skip to content

Commit

Permalink
PasswordInput: Add accessibility properties to show/hide button
Browse files Browse the repository at this point in the history
Now, after changing the show/hide button to be an icon instead of
text, we still present user-facing text to screen reader software.

Tested on iOS with VoiceOver, and implemented with help from this
article:
  https://incl.ca/show-hide-password-accessibility-and-password-hints-tutorial/
  • Loading branch information
chrisbobbe committed Feb 10, 2023
1 parent 3f3324f commit 9c473e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Icon } from './Icons';
import Input from './Input';
import type { Props as InputProps } from './Input';
import { BRAND_COLOR, HIGHLIGHT_COLOR, createStyleSheet } from '../styles';
import { TranslationContext } from '../boot/TranslationProvider';

const styles = createStyleSheet({
showPasswordButton: {
Expand Down Expand Up @@ -35,6 +36,8 @@ type Props = $ReadOnly<$Diff<InputProps,
* All props are passed through to `Input`. See `Input` for descriptions.
*/
export default function PasswordInput(props: Props): Node {
const _ = React.useContext(TranslationContext);

const [isHidden, setIsHidden] = useState<boolean>(true);

const handleShow = useCallback(() => {
Expand All @@ -56,6 +59,9 @@ export default function PasswordInput(props: Props): Node {
hitSlop={12}
style={styles.showPasswordButton}
onPress={handleShow}
accessibilityLabel={_('Show password')}
accessibilityRole="switch"
accessibilityState={{ checked: !isHidden }}
>
{({ pressed }) => (
<Icon
Expand Down
1 change: 1 addition & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Show password": "Show password",
"Quote and reply": "Quote and reply",
"{username} [said]({link_to_message}):": "{username} [said]({link_to_message}):",
"[Quoting…]": "[Quoting…]",
Expand Down

0 comments on commit 9c473e1

Please sign in to comment.