diff --git a/app/src/ui/lib/text-box.tsx b/app/src/ui/lib/text-box.tsx index a1cb4f7c56..d17a2e3953 100644 --- a/app/src/ui/lib/text-box.tsx +++ b/app/src/ui/lib/text-box.tsx @@ -4,6 +4,7 @@ import { createUniqueId, releaseUniqueId } from './id-pool' import { showContextualMenu } from '../../lib/menu-item' import { Octicon } from '../octicons' import * as OcticonSymbol from '../octicons/octicons.generated' +import { AriaLiveContainer } from '../accessibility/aria-live-container' export interface ITextBoxProps { /** The label for the input field. */ @@ -111,6 +112,11 @@ interface ITextBoxState { * Text to display in the underlying input element */ readonly value?: string + + /** + * Input just cleared via clear button. + */ + readonly valueCleared: boolean } /** An input element with app-standard styles. */ @@ -121,7 +127,7 @@ export class TextBox extends React.Component { const friendlyName = this.props.label || this.props.placeholder const inputId = createUniqueId(`TextBox_${friendlyName}`) - this.setState({ inputId, value: this.props.value }) + this.setState({ inputId, value: this.props.value, valueCleared: false }) } public componentWillUnmount() { @@ -177,7 +183,9 @@ export class TextBox extends React.Component { private onChange = (event: React.FormEvent) => { const value = event.currentTarget.value - this.setState({ value }, () => { + // Even when the new value is '', we don't want to render the aria-live + // message saying "input cleared", so we set valueCleared to false. + this.setState({ value, valueCleared: false }, () => { if (this.props.onValueChanged) { this.props.onValueChanged(value) } @@ -191,7 +199,7 @@ export class TextBox extends React.Component { this.inputElement.value = '' - this.setState({ value: '' }, () => { + this.setState({ value: '', valueCleared: true }, () => { if (this.props.onValueChanged) { this.props.onValueChanged('') } @@ -299,10 +307,17 @@ export class TextBox extends React.Component { {this.props.displayClearButton && this.state.value !== undefined && this.state.value !== '' && ( - )} + {this.state.valueCleared && ( + + )} ) }