Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d9894b2
Upgrade LG modal packages
kraenhansen Dec 18, 2025
8096983
Fix Modal to adopt LG Modal v20
kraenhansen Sep 30, 2025
1a79dee
Fix connection-form to work around LG Modal v20
kraenhansen Sep 30, 2025
baf002b
Update generative-ai to adopt marketing-modal v7
kraenhansen Sep 30, 2025
9fc6af6
Fix compass-import-export to work around LG modal v20
kraenhansen Sep 30, 2025
e1855b4
Update compass-welcome to adopt marketing-modal v7
kraenhansen Nov 5, 2025
c5274cb
Update compass-explain-plan to LG Modal v20
kraenhansen Oct 1, 2025
37a6cc7
Fix compass-crud to adopt LG modal v20
kraenhansen Oct 1, 2025
5f418d2
Update compass-schema to LG Modal v20
kraenhansen Oct 1, 2025
65831d9
Add workaround for jsdom missing HTMLDialogElement support
kraenhansen Oct 2, 2025
09eb31d
Update generative-ai to adopt LG modal v20
kraenhansen Oct 7, 2025
cd281f6
Fix fullScreen prop on derived Modal
kraenhansen Oct 7, 2025
21f3682
Remove use of deprecated backdropClassName
kraenhansen Oct 7, 2025
aa0f76f
Remove workaround for MarketingModal button disabling
kraenhansen Dec 10, 2025
5cc4946
Fix remaining components tests
kraenhansen Oct 7, 2025
5ae783d
Revert workaround for LG-5593
kraenhansen Oct 8, 2025
669e0cd
Update existing tests to handle dialog elements remaining in the DOM
kraenhansen Nov 5, 2025
e473a04
Update databases-collections to allow immediate removal of the heading
kraenhansen Nov 6, 2025
01c66a3
Update e2e tests to use waitForDisplayed over waitForExist as this is…
kraenhansen Nov 6, 2025
b343940
Update e2e tests removing [role=dialog] from confirm dialog selectors
kraenhansen Nov 7, 2025
3cdb6c7
Update e2e tests to wait for bulk delete modal to disappear
kraenhansen Nov 7, 2025
ad72a99
Update e2e tests to wait for connection form to be non-clickable in a…
kraenhansen Nov 7, 2025
5e5ce3b
Update e2e tests to fix modal regressions
kraenhansen Nov 21, 2025
2778a71
Disable pointer events on a closed modal
kraenhansen Nov 10, 2025
d1fe84b
Disable auto-focus on confirmation modal children by default
kraenhansen Nov 10, 2025
6ab317e
Add new modal specific commands
kraenhansen Nov 11, 2025
70e7015
Update E2E tests to use new modal commands instead of waitForDisplayed
kraenhansen Nov 11, 2025
f839793
Default initialFocus to "null" to avoid breaking existing modals
kraenhansen Nov 12, 2025
cf032a1
Wait for confirm button to show instead of simply expecting it
kraenhansen Nov 17, 2025
bb6ff36
Update FocusMode tests to handle LG Modal v20
kraenhansen Nov 25, 2025
3799746
Update SettingsModal tests to handle LG Modal v20
kraenhansen Nov 25, 2025
7ca774e
Clarify disabling the @typescript-eslint/no-namespace and add a TODO …
kraenhansen Nov 26, 2025
de78fec
Partial revert of ddd6d70dd59fbe8f948ea6e5ef80b6d478bc1eff
kraenhansen Nov 26, 2025
920efc6
Fix auto-focus in bulk update and delete modals
kraenhansen Dec 1, 2025
2f73260
Correcting sizing styles
kraenhansen Dec 9, 2025
c2e5d46
Correcting sizing styles more
kraenhansen Dec 9, 2025
9646d87
Use named imports
kraenhansen Dec 18, 2025
d43fc16
Upgrade confirm-modal package
kraenhansen Dec 18, 2025
dbe7574
Fix useConfirmation's confirmButtonProps types
kraenhansen Dec 18, 2025
9767e4f
Update use of ConfirmationModal
kraenhansen Dec 18, 2025
564fc1e
Set initial focus on cancel (fallback to confirm) button
kraenhansen Dec 18, 2025
6fa377d
Fix package lock
kraenhansen Dec 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disable auto-focus on confirmation modal children by default
  • Loading branch information
kraenhansen committed Dec 18, 2025
commit d1fe84b9236ae6877e66cf82cb9e7071c80ab167
15 changes: 10 additions & 5 deletions packages/compass-components/src/hooks/use-confirmation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe('use-confirmation', function () {
within(modal).getByText('This action can not be undone.')
).to.exist;
expect(within(modal).getByText('Yes')).to.exist;
expect(within(modal).getByText('Cancel')).to.exist;
const cancelElement = within(modal).getByText('Cancel');
expect(cancelElement).to.exist;
expect(cancelElement.parentElement).to.equal(document.activeElement);
});

it('handles cancel action', async function () {
Expand Down Expand Up @@ -78,10 +80,13 @@ describe('use-confirmation', function () {
screen.getByRole('button', { name: 'Confirm' })
).to.have.attribute('aria-disabled', 'true');

userEvent.type(
screen.getByRole('textbox', { name: /Type "Yes"/ }),
'Yes'
);
const textInputElement = screen.getByRole('textbox', {
name: /Type "Yes"/,
});

// The input should have focus
expect(textInputElement).to.equal(document.activeElement);
userEvent.type(textInputElement, 'Yes');

expect(
screen.getByRole('button', { name: 'Confirm' })
Expand Down
12 changes: 11 additions & 1 deletion packages/compass-components/src/hooks/use-confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export { ConfirmationModalVariant };
type ConfirmationModalProps = React.ComponentProps<typeof ConfirmationModal>;

type ConfirmationProperties = Partial<
Pick<ConfirmationModalProps, 'title' | 'variant' | 'requiredInputText'>
Pick<
ConfirmationModalProps,
'title' | 'variant' | 'requiredInputText' | 'initialFocus'
>
> & {
buttonText?: React.ReactNode;
confirmButtonProps?: Omit<ButtonProps, 'onClick'>;
Expand Down Expand Up @@ -197,6 +200,13 @@ const ConfirmationModalStateHandler: React.FunctionComponent = ({
onClick: handleCancel,
}}
requiredInputText={confirmationProps.requiredInputText ?? undefined}
initialFocus={
confirmationProps.initialFocus ??
(confirmationProps.requiredInputText
? 'auto'
: // TODO: Update this once https://jira.mongodb.org/browse/LG-5735 gets resolved
'[data-testid=lg-confirmation_modal-footer-cancel_button]')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testid is a test-only value (and even there should be used sparingly), is there a way we can implement this without relying on test-only data attributes? Pass an actual id to confirmButtonProps for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to generate an id, pass it through the props of the cancel button and use that as a selector here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So .. because the confirmButtonProps and cancelButtonProps are both based on BaseButtonProps, it's not possible to pass an id 🙄 I've asked the LG team on slack if there's a reason for that. We could leave it as-is or generate a testid in the mean time? In any case, this is a workaround until https://jira.mongodb.org/browse/LG-5735 gets resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the LG team picked this up rather quickly and there's an issue LG-5794 with a PR is already in review: mongodb/leafygreen-ui#3362

We might be able to get this pulled in as part of this PR 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR on leafygreen side is still open, but based on the changes there looks like you can already pass a normal id, it's just a type error at the moment, can we remove the usage of test-only functionality for the feature behavior and add a @ts-expect-error here? Then next time we update, we will be able to spot it and clean-up, it's easier than tracking the TODO comments

}
>
{confirmationProps.description}
{confirmationProps.warning && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
render,
screen,
waitFor,
within,
userEvent,
} from '@mongodb-js/testing-library-compass';
import { expect } from 'chai';
import React from 'react';

import { ConfirmationModalArea } from './use-confirmation';
import { showErrorDetails } from './use-error-details';

describe('use-error-details', function () {
context('showErrorDetails global function', function () {
let modal: HTMLElement;
beforeEach(async function () {
render(
<ConfirmationModalArea>
<button
type="button"
onClick={() => {
showErrorDetails({
details: { oh: 'noes' },
closeAction: 'back',
});
}}
>
Open Modal
</button>
</ConfirmationModalArea>
);
userEvent.click(screen.getByText('Open Modal'));
await waitFor(() => {
modal = screen.getByTestId('confirmation-modal');
});
});

it('renders modal with cancel button focused', function () {
expect(within(modal).getByText('Error details')).to.exist;
const confirmElement = within(modal).getByText('Back');
expect(confirmElement).to.exist;
expect(confirmElement.parentElement).to.equal(document.activeElement);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const showErrorDetails = function showErrorDetails({
buttonText: closeAction.replace(/\b\w/g, (c) => c.toUpperCase()),
confirmButtonProps: {
variant: ButtonVariant.Default,
autoFocus: true,
},
initialFocus: '[data-testid=lg-confirmation_modal-footer-confirm_button]',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, can we avoid relying on test-only attributes for real functionality?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
};
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,6 @@ describe('Collection aggregations tab', function () {
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
await errorDetailsJson.waitForDisplayed();

// exit details
// leafygreen autofocus triggers a tooltip on the error code element,
// "Tab" to remove the focus
await browser.keys('Tab');
// now click the close button
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
// wait for the modal to go away
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,6 @@ FindIterable<Document> result = collection.find(filter);`);
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
await errorDetailsJson.waitForDisplayed();

// exit details
// leafygreen autofocus triggers a tooltip on the error code element,
// "Tab" to remove the focus
await browser.keys('Tab');
// now click the close button
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
// wait for the modal to go away
Expand Down
3 changes: 0 additions & 3 deletions packages/compass-e2e-tests/tests/collection-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,6 @@ describe('Collection import', function () {
expect(await errorDetailsJson.getText()).to.include(
'schemaRulesNotSatisfied'
);
// leafygreen autofocus triggers a tooltip on the error code element,
// "Tab" to remove the focus
await browser.keys('Tab');
// now click the close button
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
// wait for the modal to go away
Expand Down