Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(SearchBox): expose formRef #3565

Merged
merged 2 commits into from Sep 26, 2022
Merged

feat(SearchBox): expose formRef #3565

merged 2 commits into from Sep 26, 2022

Conversation

esaborit4code
Copy link
Contributor

Summary
This change is motivated from a very specific use case:

I have a custom form input component which includes a SearchBox, so I my own <form> tag is wrapping the <form> that's within SearchBox. This leads to an unexpected form submission when pressing the Enter key in the search box text input.

I've already tried preventDefault and stopPropagation in the onSubmit callback available for SearchBox but it seems the way React handles events makes this useless. Getting a ref for the form allowed me to stop the submit event by using addEventListener on the ref.current element.

Since there's already an inputRef I think having a formRef won't hurt and would help others that may find themselves in a similar form nesting situation.

Result
A new formRef prop analog to current inputRef is added to SearchBox.

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

It makes sense to me, as we'd like people to mainly use the official SearchBox component, however; this should have some added tests too.

Thanks for your PR already!

@Haroenv Haroenv requested review from a team, dhayab and francoischalifour and removed request for a team July 18, 2022 11:51
Copy link
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

Hi, we'll be able to move forward after you address the comments and add a test case for formRef.

Thanks again for your contribution!

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 26, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit af3dddb:

Sandbox Source
react-instantsearch-app Configuration
hooks-example Configuration

@netlify
Copy link

netlify bot commented Sep 26, 2022

Deploy Preview for react-instantsearch ready!

Name Link
🔨 Latest commit af3dddb
🔍 Latest deploy log https://app.netlify.com/sites/react-instantsearch/deploys/63316bd27bdb3d000806c711
😎 Deploy Preview https://deploy-preview-3565--react-instantsearch.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Haroenv Haroenv changed the title Form ref feat(SearchBox): expose formRef Sep 26, 2022
@Haroenv Haroenv merged commit 1c2f46d into algolia:master Sep 26, 2022
@esaborit4code esaborit4code deleted the form-ref branch September 26, 2022 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants