fix: autofocus reject SR dialog input focus to "Yes" button (#2083)

This commit is contained in:
Danny Brown 2020-10-05 21:43:12 -04:00 committed by GitHub
parent 380acc1331
commit 6c40f581a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 14 deletions

View File

@ -443,9 +443,19 @@ function _mapDisplaySets(
), ),
actions: [ actions: [
{ id: 'cancel', text: 'Cancel', type: 'secondary' }, { id: 'cancel', text: 'Cancel', type: 'secondary' },
{ id: 'yes', text: 'Yes', type: 'primary' }, {
id: 'yes',
text: 'Yes',
type: 'primary',
classes: ['reject-yes-button'],
},
], ],
onClose: () => UIDialogService.dismiss({ id: 'ds-reject-sr' }), onClose: () => UIDialogService.dismiss({ id: 'ds-reject-sr' }),
onShow: () => {
const yesButton = document.querySelector('.reject-yes-button');
yesButton.focus();
},
onSubmit: async ({ action }) => { onSubmit: async ({ action }) => {
switch (action.id) { switch (action.id) {
case 'yes': case 'yes':

View File

@ -5,6 +5,7 @@ import classNames from 'classnames';
import Footer from './Footer'; import Footer from './Footer';
import Body from './Body'; import Body from './Body';
import Header from './Header'; import Header from './Header';
import { useEffect } from 'react';
const Dialog = ({ const Dialog = ({
title, title,
@ -12,11 +13,12 @@ const Dialog = ({
onClose, onClose,
noCloseButton, noCloseButton,
actions, actions,
onShow,
onSubmit, onSubmit,
header: HeaderComponent, header: HeaderComponent,
body: BodyComponent, body: BodyComponent,
footer: FooterComponent, footer: FooterComponent,
value: defaultValue value: defaultValue,
}) => { }) => {
const [value, setValue] = useState(defaultValue); const [value, setValue] = useState(defaultValue);
@ -27,10 +29,14 @@ const Dialog = ({
const position = 'relative'; const position = 'relative';
const width = 'w-full'; const width = 'w-full';
useEffect(() => {
if (onShow) {
onShow();
}
}, [onShow]);
return ( return (
<div <div className={classNames(theme, flex, border, outline, position, width)}>
className={classNames(theme, flex, border, outline, position, width)}
>
<HeaderComponent <HeaderComponent
title={title} title={title}
noCloseButton={noCloseButton} noCloseButton={noCloseButton}
@ -38,11 +44,7 @@ const Dialog = ({
value={value} value={value}
setValue={setValue} setValue={setValue}
/> />
<BodyComponent <BodyComponent text={text} value={value} setValue={setValue} />
text={text}
value={value}
setValue={setValue}
/>
<FooterComponent <FooterComponent
actions={actions} actions={actions}
onSubmit={onSubmit} onSubmit={onSubmit}
@ -77,7 +79,7 @@ Dialog.defaultProps = {
header: Header, header: Header,
footer: Footer, footer: Footer,
body: Body, body: Body,
value: {} value: {},
}; };
export default Dialog; export default Dialog;

View File

@ -21,7 +21,7 @@ const Footer = ({ actions, className, onSubmit, value }) => {
return ( return (
<Button <Button
key={index} key={index}
className={classNames({ 'ml-2': !isFirst })} className={classNames({ 'ml-2': !isFirst }, action.classes)}
color={isPrimary ? 'primary' : undefined} color={isPrimary ? 'primary' : undefined}
onClick={onClickHandler} onClick={onClickHandler}
style={{ transition: 'all .15s ease', height: 34 }} style={{ transition: 'all .15s ease', height: 34 }}
@ -34,7 +34,7 @@ const Footer = ({ actions, className, onSubmit, value }) => {
); );
}; };
const noop = () => { }; const noop = () => {};
Footer.propTypes = { Footer.propTypes = {
className: PropTypes.string, className: PropTypes.string,
@ -45,13 +45,14 @@ Footer.propTypes = {
text: PropTypes.string.isRequired, text: PropTypes.string.isRequired,
value: PropTypes.any, value: PropTypes.any,
type: PropTypes.oneOf(['primary', 'secondary', 'cancel']).isRequired, type: PropTypes.oneOf(['primary', 'secondary', 'cancel']).isRequired,
classes: PropTypes.arrayOf(PropTypes.string),
}) })
).isRequired, ).isRequired,
}; };
Footer.defaultProps = { Footer.defaultProps = {
onSubmit: noop, onSubmit: noop,
actions: [] actions: [],
}; };
export default Footer; export default Footer;