Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(PowerSearch): keep token presses from opening search suggestions (#7739)

zakelstorm5720ad59f6b1
diff --git a/.changeset/powersearch-token-mouse-focus.md b/.changeset/powersearch-token-mouse-focus.md
new file mode 100644
index 0000000000..97eb87f000
--- /dev/null
+++ b/.changeset/powersearch-token-mouse-focus.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Prevent pressing a built-in PowerSearch filter token with the mouse from opening search suggestions before the filter editor. Token editing, removal, and keyboard navigation retain their existing behavior.
+
+@korkt-kim
diff --git a/packages/core/src/PowerSearch/PowerSearch.test.tsx b/packages/core/src/PowerSearch/PowerSearch.test.tsx
index 6a7f57b78a..79c9416bab 100644
--- a/packages/core/src/PowerSearch/PowerSearch.test.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.test.tsx
@@ -552,6 +552,68 @@ describe('PowerSearch', () => {
});
});
+describe('filter token focus', () => {
+ it('opens the editor with the mouse without opening search suggestions', async () => {
+ const user = userEvent.setup();
+ render(
+ <PowerSearch
+ config={config}
+ filters={[
+ {
+ field: 'status',
+ operator: 'is',
+ value: {type: 'enum', value: 'open'},
+ },
+ ]}
+ onChange={() => {}}
+ />,
+ );
+ const input = screen.getByRole('combobox', {name: 'Search'});
+
+ await user.pointer({
+ target: screen.getByText('Status: is'),
+ keys: '[MouseLeft>]',
+ });
+ expect(input).not.toHaveFocus();
+ expect(input).toHaveAttribute('aria-expanded', 'false');
+ expect(
+ screen.queryByRole('button', {name: 'Apply', hidden: true}),
+ ).toBeNull();
+
+ await user.pointer({keys: '[/MouseLeft]'});
+ expect(
+ await screen.findByRole('button', {name: 'Apply', hidden: true}),
+ ).toBeInTheDocument();
+ });
+
+ it('preserves search entry and token editing with the keyboard', async () => {
+ const user = userEvent.setup();
+ render(
+ <PowerSearch
+ config={config}
+ filters={[
+ {
+ field: 'status',
+ operator: 'is',
+ value: {type: 'enum', value: 'open'},
+ },
+ ]}
+ onChange={() => {}}
+ />,
+ );
+ await user.tab();
+ expect(screen.getByRole('combobox', {name: 'Search'})).toHaveFocus();
+
+ await user.tab({shift: true}); // Remove button
+ await user.tab({shift: true}); // Token label
+ expect(screen.getByRole('button', {name: 'Status: is'})).toHaveFocus();
+ await user.keyboard('{Enter}');
+ expect(
+ await screen.findByRole('button', {name: 'Apply', hidden: true}),
+ ).toBeInTheDocument();
+ });
+});
+
describe('PowerSearch statusVariant forwarding', () => {
it('defaults to attached (status renders with data-variant="attached")', () => {
const {container} = render(
diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsx
index 598696810f..f91501832e 100644
--- a/packages/core/src/PowerSearch/PowerSearch.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.tsx
@@ -900,6 +900,15 @@ export function PowerSearch({
size={size}
icon={tokenIcon}
endContent={valueContent}
+ onMouseDown={
+ handleClick
+ ? e => {
+ // Keep a token press from entering Tokenizer's input-focus
+ // redirect. Click still edits/removes; Tab entry is unchanged.
+ e.preventDefault();
+ }
+ : undefined
+ }
onClick={
handleClick
? (e: React.MouseEvent) => {