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

Components: Tab Panel: Butttons trigger form submission #11767

Closed
TimothyBJacobs opened this issue Nov 12, 2018 · 3 comments · Fixed by #11944
Closed

Components: Tab Panel: Butttons trigger form submission #11767

TimothyBJacobs opened this issue Nov 12, 2018 · 3 comments · Fixed by #11944
Labels
[Type] Bug An existing feature does not function as intended

Comments

@TimothyBJacobs
Copy link
Member

Describe the bug
The buttons in the tab panel component trigger form submission.

To Reproduce
Steps to reproduce the behavior:

  1. Include a TabPanel within a <form> element with an onSubmit handler.
  2. Click on one of the tab panel buttons.
  3. The form's onSubmit handler is triggered.

Expected behavior
The tab to change but the form not to be submitted.

Possible Solutions

  1. preventDefault on the click event.
  2. Add a type="button" to the TabButton component.
  3. Allow passing additional props to the TabButton via the tabs prop.

Desktop (please complete the following information):

  • OS: macOS
  • Browser Safari, Chrome, etc...
  • Version 12
@designsimply designsimply added the Needs Technical Feedback Needs testing from a developer perspective. label Nov 12, 2018
@designsimply
Copy link
Member

Any chance you can provide a more detailed code example for step one? I would like to help test but need more specific testing instructions as I am new to testing custom code cases like this one.

@TimothyBJacobs
Copy link
Member Author

Sure!

Clicking on one of the tab panel buttons will cause an alert to appear.

import {TabPanel} from '@wordpress/components';

function App() {
	return (
		<form onSubmit={alert}>
			<TabPanel className="my-tab-panel"
					  activeClass="active-tab"
					  tabs={ [
						  {
							  name: 'tab1',
							  title: 'Tab 1',
							  className: 'tab-one',
						  },
						  {
							  name: 'tab2',
							  title: 'Tab 2',
							  className: 'tab-two',
						  },
					  ] }>
				{
					( tab ) => <p>{ tab.title }</p>
				}
			</TabPanel>
		</form>
	)
}

@designsimply
Copy link
Member

Thanks! I thought I could copy paste in a test but I am not sure where to put the code. I'll leave the Needs Technical Feedback label and wait for a developer who knows a bit more about how to test this to respond. 😊

@designsimply designsimply removed the Needs Technical Feedback Needs testing from a developer perspective. label Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants