Skip to content

Conversation

emarchak
Copy link
Contributor

(Try 2 for CodeCov)

WHY are these changes introduced?

We're using the TextField component inside a very long form. When switching context (e.g. changing the form data but keeping the form), we need to update the values of the form..

When doing so, the aria-live state of the character counters is causing them to be read out one after another without any context. I'm setting the aria-live state to off unless the TextField has focus.

Feel free to slack @emarchak for more context on this. Related to the same problem as #1699.

WHAT is this pull request doing?

I'm piggy-backing off of the existing focus state in the TextField component to toggle between off and polite to the character count.

How to 🎩

  1. Set up the playground with the following code. You'll get an input field with a character count and a button that says "Update textfield."
  2. Boot up your screen reader, and edit the text in the textfield
    • You should hear the screen reader read out the character count as your typing.
  3. Tab out of the text field and click the "Update textfield." button.
    • You should not hear the screen reader read out the new character count.

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React from 'react';
import {TextField, Button} from '../src';

interface State {
  value: string;
}

export default class Playground extends React.Component<State> {
  constructor(props) {
    super(props);
    this.state = {
      value: 'This is this original value.',
    };
  }

  handleTextChange = (value) => {
    this.setState({value});
  };

  updateTextField = () => {
    this.setState({value: 'This is a new value'});
  };

  render() {
    const {value} = this.state;

    return (
      <React.Fragment>
        <TextField
          label="Input Value name"
          value={value}
          showCharacterCount
          onChange={this.handleTextChange}
        />

        <Button onClick={this.updateTextField}>Update textfield</Button>
      </React.Fragment>
    );
  }
}

🎩 checklist

cc @Shopify/accessibility

@BPScott BPScott temporarily deployed to polaris-react-pr-1720 June 20, 2019 15:21 Inactive
@emarchak emarchak force-pushed the textfield-arialive-character-count-toggle branch from 18625eb to aee544a Compare June 20, 2019 15:22
@BPScott BPScott temporarily deployed to polaris-react-pr-1720 June 20, 2019 15:22 Inactive
@emarchak emarchak force-pushed the textfield-arialive-character-count-toggle branch from aee544a to 044572b Compare June 20, 2019 15:23
@BPScott BPScott temporarily deployed to polaris-react-pr-1720 June 20, 2019 15:23 Inactive
@emarchak emarchak requested a review from dpersing June 20, 2019 15:23
Copy link

@dpersing dpersing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞

@emarchak emarchak merged commit b9c6249 into master Jun 20, 2019
@kaelig kaelig deleted the textfield-arialive-character-count-toggle branch July 12, 2019 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants