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

prevent modalBody render if no children provided #1500

Merged
merged 5 commits into from
Jan 31, 2019

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Jan 30, 2019

Summary

Resolves #1382.

Prevents empty EuiModalBody from rendering in EuiConfimModal

Checklist

- [ ] This was checked in mobile
- [ ] This was checked in IE11
- [ ] This was checked in dark mode
- [ ] Any props added have proper autodocs

  • Documentation examples were added
  • A changelog entry exists and is marked appropriately
  • This was checked for breaking changes and labeled appropriately
  • Jest tests were updated or added to match the most common scenarios

- [ ] This was checked against keyboard-only and screenreader scenarios
- [ ] This required updates to Framer X components

@@ -75,7 +75,7 @@ export class EuiConfirmModal extends Component {

let message;

if (typeof children === 'string') {
if (typeof children === 'string' && !!children.length) {
Copy link
Contributor

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.

Copy link
Contributor

@cjcenizal cjcenizal Jan 31, 2019

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. 😄

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 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 ' '.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🚀 This looks great! Thanks for making this change. What do you think of adding an example so it's easy for people to see how it looks?

image

@cchaos
Copy link
Contributor

cchaos commented Jan 31, 2019

If you do add a doc example, I wouldn't label it as empty since that is a misnomer for what the example is actually achieving. I'd label it something like title only.

@thompsongl
Copy link
Contributor Author

New thought: We can do this without introducing breaking changes (:tada:)

A CSS-only solution exists that would:

  1. Leave all relevant data-test-subj attributes in place for testing framework selection
  2. "Hide" the modal body via conditional className addition

I'll get changes pushed soon

@cjcenizal
Copy link
Contributor

We can do this without introducing breaking changes

I was under the impression that the change as-is (removing the DOM element) was not a breaking change -- what am I missing?

@thompsongl
Copy link
Contributor Author

@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 data-test-subj, which is likely to break integration tests.

@chandlerprall
Copy link
Contributor

chandlerprall commented Jan 31, 2019

Perhaps curiously, I'm okay with that change not being breaking - if a test cares about confirmModalBodyText and it isn't passing content in, that test isn't a very good one. Copying from my reply above: that reflects the spirit of the component

@cchaos
Copy link
Contributor

cchaos commented Jan 31, 2019

Please, completely ignore my comment. Go with the original PR......

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Approved!!

@cjcenizal
Copy link
Contributor

@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?

@thompsongl
Copy link
Contributor Author

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.

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM!

@thompsongl thompsongl merged commit 085dc4f into elastic:master Jan 31, 2019
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.

4 participants