Focus quantity input when entering edit mode.

Makes the keyboard-first and screen reader experience much better.
This commit is contained in:
Jeff Stieler 2019-04-03 18:05:19 -06:00
parent 9bcbda0f98
commit c3ef41fc12
1 changed files with 16 additions and 7 deletions

View File

@ -3,7 +3,7 @@
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button, TextControl } from '@wordpress/components';
import { BaseControl, Button } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withDispatch } from '@wordpress/data';
@ -32,6 +32,10 @@ class ProductStockCard extends Component {
this.updateStock = this.updateStock.bind( this );
}
componentDidUpdate() {
this.quantityInput && this.quantityInput.focus();
}
beginEdit() {
this.setState( { editing: true } );
}
@ -86,12 +90,17 @@ class ProductStockCard extends Component {
if ( editing ) {
return (
<Fragment>
<TextControl
className="woocommerce-stock-activity-card__edit-quantity"
type="number"
value={ quantity }
onChange={ this.onQuantityChange }
/>
<BaseControl className="woocommerce-stock-activity-card__edit-quantity">
<input
className="components-text-control__input"
type="number"
value={ quantity }
onChange={ this.onQuantityChange }
ref={ input => {
this.quantityInput = input;
} }
/>
</BaseControl>
<span>{ __( 'in stock', 'woocommerce-admin' ) }</span>
</Fragment>
);