From 6c40f581a614487d35add95c15a2deac82b9d384 Mon Sep 17 00:00:00 2001 From: Danny Brown Date: Mon, 5 Oct 2020 21:43:12 -0400 Subject: [PATCH] fix: autofocus reject SR dialog input focus to "Yes" button (#2083) --- .../PanelStudyBrowserTracking.jsx | 12 +++++++++- platform/ui/src/components/Dialog/Dialog.jsx | 22 ++++++++++--------- platform/ui/src/components/Dialog/Footer.js | 7 +++--- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/PanelStudyBrowserTracking.jsx b/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/PanelStudyBrowserTracking.jsx index 598515197..370feedcc 100644 --- a/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/PanelStudyBrowserTracking.jsx +++ b/extensions/measurement-tracking/src/panels/PanelStudyBrowserTracking/PanelStudyBrowserTracking.jsx @@ -443,9 +443,19 @@ function _mapDisplaySets( ), actions: [ { 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' }), + onShow: () => { + const yesButton = document.querySelector('.reject-yes-button'); + + yesButton.focus(); + }, onSubmit: async ({ action }) => { switch (action.id) { case 'yes': diff --git a/platform/ui/src/components/Dialog/Dialog.jsx b/platform/ui/src/components/Dialog/Dialog.jsx index 868b1b5c3..d1b615008 100644 --- a/platform/ui/src/components/Dialog/Dialog.jsx +++ b/platform/ui/src/components/Dialog/Dialog.jsx @@ -5,6 +5,7 @@ import classNames from 'classnames'; import Footer from './Footer'; import Body from './Body'; import Header from './Header'; +import { useEffect } from 'react'; const Dialog = ({ title, @@ -12,11 +13,12 @@ const Dialog = ({ onClose, noCloseButton, actions, + onShow, onSubmit, header: HeaderComponent, body: BodyComponent, footer: FooterComponent, - value: defaultValue + value: defaultValue, }) => { const [value, setValue] = useState(defaultValue); @@ -27,10 +29,14 @@ const Dialog = ({ const position = 'relative'; const width = 'w-full'; + useEffect(() => { + if (onShow) { + onShow(); + } + }, [onShow]); + return ( -
+
- + { return (