Skip to content

fix: Various fixes to the ModalActions component#615

Merged
gnapse merged 1 commit intomainfrom
ernesto/modal-improvements
Jan 5, 2022
Merged

fix: Various fixes to the ModalActions component#615
gnapse merged 1 commit intomainfrom
ernesto/modal-improvements

Conversation

@gnapse
Copy link
Copy Markdown
Contributor

@gnapse gnapse commented Dec 7, 2021

Closes #613
Supersedes PR #614

Short description

This PR performs the following changes on the ModalActions component:

  • ignore null children
  • flatten children wrapped in React fragments
  • removes the unneeded extra div wrapping each child element (following the same logic described here).

Additionally, this removes an extra Box wrapping the main element rendered by Inline. I was surprised to see it, and did several manual testing (both in the storybook, and running twist-web with my local version of Reactist with these changes in place) and, as I suspected, this outer div is not needed.

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

Queued, to be included in an upcoming release.

@gnapse gnapse requested a review from a team December 7, 2021 16:51
@gnapse gnapse self-assigned this Dec 7, 2021
@gnapse gnapse requested review from nats12 and removed request for a team December 7, 2021 16:51
<ModalActions data-testid="modal-actions">
<button>OK</button>
<button>Cancel</button>
{null}
Copy link
Copy Markdown
Contributor

@nats12 nats12 Dec 8, 2021

Choose a reason for hiding this comment

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

Wouldn't this make it harder to debug null values as a consumer? Say we are passing down a div containing a null value. We would at least be able to see that the div is correctly being rendered, it just doesn't have a value. Not against it though, just wanted to learn more regarding the decision to ignore them

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.

Say we are passing down a div containing a null value.

What do you mean with "a div containing a null value"? And what do you mean with "debug null values as a consumer"?

Copy link
Copy Markdown
Contributor

@nats12 nats12 Dec 8, 2021

Choose a reason for hiding this comment

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

What I understand from the above is that if we have:

<ModalActions data-testid="modal-actions">
                <button>{some null value}</button>
</ModalActions>

We would see:

<ModalActions data-testid="modal-actions">
                <button>OK</button>
                <button>Cancel</button>
 </ModalActions>

Is that right? Or would we render a third empty button tag?

And what do you mean with "debug null values as a consumer"?

If I've understood it right and the above example is how it would work, wouldn't it be confusing to eliminate the empty button tag with the null value? Especially as we inspect the DOM to see why it hasn't rendered?

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.

What the above example shows is that if one of the direct children of ModalActions is null, it will not generate a "slot" in the sequence of inlined elements that are spaced out. It has nothing to do with having non-null children that have their children null.

If this component that we're testing receives a <button>{some null value}</button>, it has no way of knowing that the component has null children. It only knows if its own children are null.

Copy link
Copy Markdown
Contributor

@nats12 nats12 left a comment

Choose a reason for hiding this comment

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

Looks good! Just left a question around the ignoring of null children, but nothing that's blocking

@gnapse gnapse force-pushed the ernesto/modal-improvements branch from 1570e0e to fa570d6 Compare December 9, 2021 11:59
@henningmu
Copy link
Copy Markdown
Contributor

@gnapse let's merge this?

@gnapse
Copy link
Copy Markdown
Contributor Author

gnapse commented Jan 4, 2022

@gnapse let's merge this?

Thanks for the reminder, I had forgotten about this.

I'll do a smoke test running Twist locally against this branch, to make sure that it does not break anything. I think I did this at some point, but I'm not 100% sure.

@gnapse
Copy link
Copy Markdown
Contributor Author

gnapse commented Jan 4, 2022

I found no major consequences. The only noticeable thing is that under certain situations (e.g. a Inline directly inside a Stack) we may need to manually wrap the Inline inside a div or Box. I only found one instance of this happening in Twist, and in any case the actual visual consequence is almost not noticeable.

CleanShot 2022-01-04 at 11 36 48

This is an expected consequence of the removal of this extra wrapper, as documented here.

I'll fix it in Twist in the PR that will upgrade to the new Reactist version, which I'll create this week.

@gnapse gnapse merged commit 02bd83e into main Jan 5, 2022
@gnapse gnapse deleted the ernesto/modal-improvements branch January 5, 2022 14:49
@gnapse gnapse mentioned this pull request Jan 5, 2022
4 tasks
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