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

experimental/SelectPanel: Don't render form if nested inside form #4552

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented May 2, 2024

Note

If we want, we can wait until we figure out the semantics for https://github.com/github/primer/issues/3183 to find out if we want to render a <form> element at all

Bug:

SelectPanel renders a <form> element inside a <dialog>. We also do allow the use of SelectPanel inside with FormControl (which is expected to be inside a <form> already)

This would create invalid DOM nesting of <form> nested inside <form>. react-dom throws a validation warning on the console

Fix:

If SelectPanel is nested inside FormControl, it will now render a <div> instead of <form>.

Note: If someone is using SelectPanel in a custom form without FormControl, this PR would not be able to catch that scenario.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@siddharthkp siddharthkp requested a review from joshblack May 2, 2024 14:01
@siddharthkp siddharthkp self-assigned this May 2, 2024
@siddharthkp siddharthkp requested a review from a team as a code owner May 2, 2024 14:01
Copy link

changeset-bot bot commented May 2, 2024

🦋 Changeset detected

Latest commit: bd12791

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@siddharthkp siddharthkp marked this pull request as draft May 2, 2024 14:02
Copy link
Contributor

github-actions bot commented May 2, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 87.98 KB (0%)
packages/react/dist/browser.umd.js 88.28 KB (0%)

Copy link
Contributor

@JeffreyKozik JeffreyKozik 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 fixing this. As you mentioned, it might be better to not render a <form> element for SelectPanel at all, and that would fix this issue if someone had SelectPanel nested within a <form> other than FormControl. However, I'm not sure what the other implications of doing so are.

<FormControl.Label>SelectPanel within FormControl</FormControl.Label>
<SelectPanel title="Choose a tag" selectionVariant="instant" onSubmit={onSubmit}>
<SelectPanel.Button leadingVisual={TagIcon}>{selectedTag || 'Choose a tag'}</SelectPanel.Button>
<form>
Copy link
Contributor

Choose a reason for hiding this comment

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

Now this error is triggered when clicking the SelectPanel 👍

<form> cannot appear as a descendant of <form>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this error have been showing without needing to wrap <form> around <FormControl>? Do we know why it was occurring in Dotcom and not Storybook and if there's a way to achieve parity between the two to avoid future problems?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't this error have been showing without needing to wrap <form> around <FormControl>

Nope, because FormControl does not render a form, there was no outer/parent <form>

Do we know why it was occurring in Dotcom and not Storybook and if there's a way to achieve parity between the two to avoid future problems?

The dotcom version had an outer <form>, storybook didn't until now. FormControl should probably warn you if you are using it without a <form> 🤔

@@ -306,8 +312,8 @@ const Panel: React.FC<SelectPanelProps> = ({
}}
>
<Box
as="form"
method="dialog"
as={isInsideForm ? 'div' : 'form'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to write a test for this to ensure we're not getting the error again? Or is it not detectable through testing?

@siddharthkp siddharthkp added the patch release bug fixes, docs, housekeeping label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch release bug fixes, docs, housekeeping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants