Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure Dialogs do not render close button when onClose callback is not provided #1045

Merged
merged 1 commit into from
May 23, 2023

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented May 22, 2023

Closes #1044

This PR changes the logic in Dialog to make sure an onClose callback is not passed down to the Panel, if the Dialog itself did not get one.

@acelaya acelaya requested a review from lyzadanger May 22, 2023 15:26
@@ -216,7 +215,7 @@ const Dialog = function Dialog({
buttons={buttons}
fullWidthHeader={true}
icon={icon}
onClose={closeHandler}
onClose={isClosableDialog ? closeHandler : undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could just have done onClose ? closeHandler : undefined, but I feel starting with isClosableDialog explains better the "why".

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's fine.

const wrapper = mount(<Dialog title="My dialog" />);
assert.isFalse(wrapper.find('CancelIcon').exists());
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails in main.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job, thanks!

@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Merging #1045 (dc402c8) into main (c156fce) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1045   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           53        53           
  Lines          715       715           
  Branches       251       251           
=========================================
  Hits           715       715           
Impacted Files Coverage Δ
src/components/feedback/Dialog.tsx 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more


const closeHandler = useCallback(() => {
if (TransitionComponent) {
// When a TransitionComponent is provided, the actual "onClose" will be
// called by that component, once the "out" transition has finished
setTransitionComponentVisible(false);
} else {
onClose();
onClose?.();
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically we know that onClose is present at this point, but TS wouldn't, I suppose. I'm fine leaving this as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's actually a good point 🤔

I kind-of want to give this a thought and see if I can find a way to make TS know this is actually set at this point.

@@ -216,7 +215,7 @@ const Dialog = function Dialog({
buttons={buttons}
fullWidthHeader={true}
icon={icon}
onClose={closeHandler}
onClose={isClosableDialog ? closeHandler : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's fine.

const wrapper = mount(<Dialog title="My dialog" />);
assert.isFalse(wrapper.find('CancelIcon').exists());
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job, thanks!

@acelaya acelaya merged commit 8ba1303 into main May 23, 2023
@acelaya acelaya deleted the fix-non-closable-dialog branch May 23, 2023 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dialog is rendering a close button when no onClose is provided
2 participants