Skip to content

fix: Improve ModalActions behaviour with null child items#614

Closed
scottlovegrove wants to merge 6 commits intomainfrom
scottl/modal-actions
Closed

fix: Improve ModalActions behaviour with null child items#614
scottlovegrove wants to merge 6 commits intomainfrom
scottl/modal-actions

Conversation

@scottlovegrove
Copy link
Copy Markdown
Contributor

@scottlovegrove scottlovegrove commented Dec 5, 2021

Closes #613

Short description

This change ensures that if child items passed into the ModalActions component are null, then they do not have an empty div, with spacing, created. It also ensures that if all child items passed into the component are null, then just don't create the footer in the first place.

PR Checklist

  • Added tests for bugs / new features
  • Updated docs (storybooks, readme)
  • Executed npm run validate and made sure no errors / warnings were shown
  • Described changes in CHANGELOG.md
  • Bumped version in package.json and package-lock.json (npm --no-git-tag-version version <major|minor|patch>) ref
  • Updated all static build artifacts (npm run build-all)

Versioning

This is not a breaking change, but I haven't updated the version.

@scottlovegrove scottlovegrove requested a review from a team December 5, 2021 17:32
@scottlovegrove scottlovegrove self-assigned this Dec 5, 2021
@scottlovegrove scottlovegrove requested review from Bloomca and gnapse and removed request for a team December 5, 2021 17:32
Comment thread src/new-components/modal/modal.tsx Outdated
{React.Children.map(children, (child) => (
<div>{child}</div>
))}
{childItems.map((child, i) => (child ? <div key={i}>{child}</div> : null))}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need to check here for falsy values as we filter them out above already. All child should be truthy 👍


A question for @gnapse: why do we need to wrap the children in divs in the first place? Shouldn't Inline work with anything we throw at it? And if not should we pass this burden to the user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need to check here for falsy values as we filter them out above already. All child should be truthy 👍

Say hello to the original fix 😄 I'll remove that check now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we need to wrap the children in divs in the first place? Shouldn't Inline work with anything we throw at it? And if not should we pass this burden to the user?

Nope. This was a compromise to avoid having Inline and Stack generate excessive markup all the time. See https://github.com/Doist/reactist/wiki/Simplified-markup-of-the-Stack-and-Inline-components

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense and awesome that we have documentation on this ❤️

Copy link
Copy Markdown
Contributor

@gnapse gnapse left a comment

Choose a reason for hiding this comment

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

Thanks for this, Scott. It certainly is an oversight.

However, this has made me realize that there's another related oversight that we might as well fix alongside the original issue. Imagine something like this:

<ModalActions>
  {canSubmit ? (
    <>
      <Button type="submit">Delete one</Button>
      <Button type="submit">Delete all</Button>
    </>
  ) : null}
  <Button>Cancel</Button>
</ModalActions>

The first two buttons, being wrapped by a fragment, will be part of a single child of the Inline wrapper, thus lacking a spacing between them. What a consume of this component would expect is that the above ModalAction is treated as a Inline with 3 spaced-out children when the canSubmit condition is true.

A better fix for this issue goes along the lines of using react-keyed-flatten-children. An example of this is present in the Stack component implementation.

Since Scott is on time off for a few weeks, I may take this over and do the change myself.

@gnapse
Copy link
Copy Markdown
Contributor

gnapse commented Dec 7, 2021

Closed without merging, superseded by #615.

@gnapse gnapse closed this Dec 7, 2021
@scottlovegrove scottlovegrove deleted the scottl/modal-actions branch February 3, 2022 09:16
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.

ModalActions: Don't add spacing for null child items

3 participants