Skip to content

Commit 9c473e1

Browse files
committed
PasswordInput: Add accessibility properties to show/hide button
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/
1 parent 3f3324f commit 9c473e1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/common/PasswordInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Icon } from './Icons';
77
import Input from './Input';
88
import type { Props as InputProps } from './Input';
99
import { BRAND_COLOR, HIGHLIGHT_COLOR, createStyleSheet } from '../styles';
10+
import { TranslationContext } from '../boot/TranslationProvider';
1011

1112
const styles = createStyleSheet({
1213
showPasswordButton: {
@@ -35,6 +36,8 @@ type Props = $ReadOnly<$Diff<InputProps,
3536
* All props are passed through to `Input`. See `Input` for descriptions.
3637
*/
3738
export default function PasswordInput(props: Props): Node {
39+
const _ = React.useContext(TranslationContext);
40+
3841
const [isHidden, setIsHidden] = useState<boolean>(true);
3942

4043
const handleShow = useCallback(() => {
@@ -56,6 +59,9 @@ export default function PasswordInput(props: Props): Node {
5659
hitSlop={12}
5760
style={styles.showPasswordButton}
5861
onPress={handleShow}
62+
accessibilityLabel={_('Show password')}
63+
accessibilityRole="switch"
64+
accessibilityState={{ checked: !isHidden }}
5965
>
6066
{({ pressed }) => (
6167
<Icon

static/translations/messages_en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"Show password": "Show password",
23
"Quote and reply": "Quote and reply",
34
"{username} [said]({link_to_message}):": "{username} [said]({link_to_message}):",
45
"[Quoting…]": "[Quoting…]",

0 commit comments

Comments
 (0)