-
Notifications
You must be signed in to change notification settings - Fork 843
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
prevent modalBody render if no children provided #1500
prevent modalBody render if no children provided #1500
Conversation
@@ -75,7 +75,7 @@ export class EuiConfirmModal extends Component { | |||
|
|||
let message; | |||
|
|||
if (typeof children === 'string') { | |||
if (typeof children === 'string' && !!children.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer testing explicitly for children.length > 0
. Less mental hoops to jump through when reading through the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the thinking behind this change, but what if the user provides a string of whitespace like ' '
? Then we could make this children.trim().length > 0
. Though it's a bit of a slippery slope -- at which point do we stop sanitizing input and just trust the consumer to provide us with what they want?
For questions like this, my reasoning tends to take a draconian approach: "This component can't know what the consumer intends, but it can provide predictable behavior. I can't think of a reason for why the consumer would want to provide an empty string, but there is a limit to my imagination and no limit to the number of consumers' use cases for this component now and in the future. Therefore, providing predictable behavior and making no assumptions about the consumer's intention, even if it seems silly, is the optimal choice."
Not saying we shouldn't do this, just thought I'd share how I would approach things. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change reflects the spirit of the component. An empty string is empty contents, but a non-empty string (including whitespace) is contentful. This provides the predictability of the component (''
is empty) while allowing flexibility of passing ' '
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do add a doc example, I wouldn't label it as |
New thought: We can do this without introducing breaking changes (:tada:) A CSS-only solution exists that would:
I'll get changes pushed soon |
I was under the impression that the change as-is (removing the DOM element) was not a breaking change -- what am I missing? |
@cjcenizal This is something of a discussion with @chandlerprall, but testing hooks are considered part of EUI's public API. Conditionally rendering the modal body removes its child |
Perhaps curiously, I'm okay with that change not being breaking - if a test cares about |
Please, completely ignore my comment. Go with the original PR...... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved!!
@thompsongl @chandlerprall I was thinking along the same lines as Chandler -- if anything, a test would expect the body to be empty and therefore would want to assert that the body isn't rendered. I think you could consider this a bug fix. If consumers are dependent upon a bug, which we then fix, would we consider that breaking? |
Alright y'all. Thank you for the discussion and your perspectives on how tests impact breaking changes. I've remained with the original changeset and added a docs example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Resolves #1382.
Prevents empty
EuiModalBody
from rendering inEuiConfimModal
Checklist
- [ ] This was checked in mobile- [ ] This was checked in IE11- [ ] This was checked in dark mode- [ ] Any props added have proper autodocs- [ ] This was checked against keyboard-only and screenreader scenarios- [ ] This required updates to Framer X components