Autofocus alert cancel button

This commit is contained in:
Gregory Schier 2018-02-08 17:23:38 +08:00
parent f746eff4ca
commit c579e1a6e0
2 changed files with 20 additions and 3 deletions

View File

@ -86,7 +86,7 @@ class ResponseHistoryDropdown extends PureComponent {
<Dropdown ref={this._setDropdownRef}
key={activeResponse ? activeResponse._id : 'n/a'} {...extraProps}>
<DropdownButton className="btn btn--super-compact tall" title="Response history">
{!isLatestResponseActive ? <i className="fa fa-thumb-tack"/> : null}
{!isLatestResponseActive ? <i className="fa fa-thumb-tack"/> : <i className="fa fa-clock-o"/>}
<i className="fa fa-caret-down"/>
</DropdownButton>
<DropdownDivider>Response History</DropdownDivider>

View File

@ -30,12 +30,25 @@ class AlertModal extends PureComponent {
this.modal.hide();
}
setCancelRef (n) {
this._cancel = n;
}
setOkRef (n) {
this._ok = n;
}
show (options = {}) {
const {title, message, addCancel} = options;
this.setState({title, message, addCancel});
this.modal.show();
// Need to do this after render because modal focuses itself too
setTimeout(() => {
this._cancel && this._cancel.focus();
}, 100);
return new Promise(resolve => {
this._okCallback = resolve;
});
@ -52,8 +65,12 @@ class AlertModal extends PureComponent {
</ModalBody>
<ModalFooter>
<div>
{addCancel ? <button className="btn" onClick={this.hide}>Cancel</button> : null}
<button className="btn" onClick={this._handleOk}>
{addCancel ? (
<button className="btn" ref={this.setCancelRef} onClick={this.hide}>
Cancel
</button>
) : null}
<button className="btn" ref={this.setOkRef} onClick={this._handleOk}>
Ok
</button>
</div>