Skip to content

feat(autocomplete): replace "cancel" with a back button in detached mode#6942

Open
Haroenv wants to merge 1 commit intomasterfrom
feat/aaa-detached-back
Open

feat(autocomplete): replace "cancel" with a back button in detached mode#6942
Haroenv wants to merge 1 commit intomasterfrom
feat/aaa-detached-back

Conversation

@Haroenv
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv commented Mar 26, 2026

In preparation for ai mode, moving from an explicit cancel button to a back button that replaces the submit button (there's already a search button on the keyboard) allows us to get rid of the previous cancel button.

the loading icon still replaces the back button like it used to with submit.

This is still allowed as we are in experimental autocomplete.

In preparation for ai mode, moving from an explicit cancel button to a back button that replaces the submit button (there's already a search button on the keyboard) allows us to get rid of the previous cancel button.

the loading icon still replaces the back button like it used to with submit.

This is still allowed as we are in experimental autocomplete.
Copilot AI review requested due to automatic review settings March 26, 2026 13:24
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 26, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6942

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6942

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6942

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6942

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6942

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6942

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6942

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6942

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6942

commit: 91022fd

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the experimental Autocomplete detached-mode UX by removing the detached “Cancel” button and introducing a dedicated back button inside the search input, aligning detached-mode controls with upcoming AI-mode behavior.

Changes:

  • Introduces a new back button (and BackIcon) for detached mode, replacing the prior detached cancel button UI.
  • Wires detached close behavior through shared handleCancel logic and passes new props through React / InstantSearch wrappers.
  • Updates styling and test suites to reflect the new DOM structure and removed cancel button.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/common/widgets/autocomplete/options.tsx Updates integration expectations for back button vs removed detached cancel button.
packages/react-instantsearch/src/widgets/Autocomplete.tsx Adds detached back-button wiring via new AutocompleteSearch props and consolidates cancel/close handling.
packages/react-instantsearch/src/components/AutocompleteSearch.tsx Threads new onSubmit / detached-related props through to UI component layer.
packages/instantsearch.js/src/widgets/autocomplete/autocomplete.tsx Mirrors detached back-button wiring and cancel/close consolidation for InstantSearch.js widget.
packages/instantsearch.css/src/components/autocomplete.scss Adds styling for .ais-AutocompleteBackButton and removes detached cancel button styles.
packages/instantsearch-ui-components/src/components/autocomplete/icons.tsx Adds BackIcon for the detached back button.
packages/instantsearch-ui-components/src/components/autocomplete/tests/AutocompleteSearch.test.tsx Adds unit tests validating detached back button rendering and removal of detached cancel button.
packages/instantsearch-ui-components/src/components/autocomplete/AutocompleteSearch.tsx Implements detached back button rendering and new props (onSubmit, isDetached, submitTitle).
packages/instantsearch-ui-components/src/components/autocomplete/AutocompleteDetachedFormContainer.tsx Removes rendering of the detached cancel button.
packages/instantsearch-ui-components/src/components/autocomplete/Autocomplete.tsx Clarifies that detachedCancelButton class name is retained for backwards compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to +22
userProps: AutocompleteDetachedFormContainerProps
) {
const { children, classNames = {}, onCancel, translations } = userProps;
const { children, classNames = {} } = userProps;
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

AutocompleteDetachedFormContainer no longer renders/uses onCancel and translations, but those props are still required by AutocompleteDetachedFormContainerProps. This forces new consumers to pass unused values and makes the public API misleading. Consider making these props optional (and/or marking them deprecated in the type) now that the cancel button isn’t rendered.

Copilot uses AI. Check for mistakes.
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.

is it not still using it for the title of the back button? @copilot do you mind explaining?

Comment on lines 33 to +50
<form
className="ais-AutocompleteForm"
action=""
noValidate
role="search"
onSubmit={(e) => e.preventDefault()}
onSubmit={(e) => {
e.preventDefault();
}}
onReset={() => inputRef.current?.focus()}
>
<div className="ais-AutocompleteInputWrapperPrefix">
{isBackButton && (
<button
className="ais-AutocompleteBackButton"
type="button"
title={resolvedCancelTitle}
onClick={onSubmit}
hidden={isSearchStalled}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The new onSubmit prop name is misleading here: it isn’t invoked on the form submit event (the form handler only preventDefault()), and it’s only used as the back-button click handler in detached mode. This can confuse consumers and makes it easy to wire the wrong behavior. Consider either calling the callback from the form onSubmit handler (when appropriate) or renaming the prop to something like onBack/onCancel (potentially keeping onSubmit as a deprecated alias).

Copilot uses AI. Check for mistakes.
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.

2 participants