Skip to content

Commit 1b1d65e

Browse files
committed
Disable auto-focus on confirmation modal children by default
1 parent e0d5f3d commit 1b1d65e

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

packages/compass-components/src/hooks/use-confirmation.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export { ConfirmationModalVariant };
1818
type ConfirmationModalProps = React.ComponentProps<typeof ConfirmationModal>;
1919

2020
type ConfirmationProperties = Partial<
21-
Pick<ConfirmationModalProps, 'title' | 'variant' | 'requiredInputText'>
21+
Pick<
22+
ConfirmationModalProps,
23+
'title' | 'variant' | 'requiredInputText' | 'initialFocus'
24+
>
2225
> & {
2326
buttonText?: React.ReactNode;
2427
confirmButtonProps?: Omit<ButtonProps, 'onClick'>;
@@ -188,6 +191,7 @@ const ConfirmationModalStateHandler: React.FunctionComponent = ({
188191
children: confirmationProps.buttonText ?? 'Confirm',
189192
onClick: handleConfirm,
190193
...confirmationProps.confirmButtonProps,
194+
'data-lgid': 'lg-confirmation_modal-footer-confirm_button',
191195
}}
192196
cancelButtonProps={{
193197
className: confirmationProps.hideCancelButton
@@ -196,6 +200,10 @@ const ConfirmationModalStateHandler: React.FunctionComponent = ({
196200
onClick: handleCancel,
197201
}}
198202
requiredInputText={confirmationProps.requiredInputText ?? undefined}
203+
initialFocus={
204+
confirmationProps.initialFocus ??
205+
'[data-lgid=lg-confirmation_modal-footer-confirm_button]'
206+
}
199207
>
200208
{confirmationProps.description}
201209
{confirmationProps.warning && (

packages/compass-components/src/hooks/use-error-details.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const showErrorDetails = function showErrorDetails({
2525
buttonText: closeAction.replace(/\b\w/g, (c) => c.toUpperCase()),
2626
confirmButtonProps: {
2727
variant: ButtonVariant.Default,
28-
autoFocus: true,
2928
},
3029
});
3130
};

packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,6 @@ describe('Collection aggregations tab', function () {
676676
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
677677
await errorDetailsJson.waitForDisplayed();
678678

679-
// exit details
680-
// leafygreen autofocus triggers a tooltip on the error code element,
681-
// "Tab" to remove the focus
682-
await browser.keys('Tab');
683679
// now click the close button
684680
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
685681
// wait for the modal to go away

packages/compass-e2e-tests/tests/collection-documents-tab.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,6 @@ FindIterable<Document> result = collection.find(filter);`);
727727
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
728728
await errorDetailsJson.waitForDisplayed();
729729

730-
// exit details
731-
// leafygreen autofocus triggers a tooltip on the error code element,
732-
// "Tab" to remove the focus
733-
await browser.keys('Tab');
734730
// now click the close button
735731
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
736732
// wait for the modal to go away

packages/compass-e2e-tests/tests/collection-import.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,6 @@ describe('Collection import', function () {
595595
expect(await errorDetailsJson.getText()).to.include(
596596
'schemaRulesNotSatisfied'
597597
);
598-
// leafygreen autofocus triggers a tooltip on the error code element,
599-
// "Tab" to remove the focus
600-
await browser.keys('Tab');
601598
// now click the close button
602599
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
603600
// wait for the modal to go away

0 commit comments

Comments
 (0)