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

fix(atomic): don't redirect when hovering a instant result & pressing Enter #4938

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/atomic/scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ startServers();

// Watch the src folder for changes
watch('src', {recursive: true}, async (_, filename) => {
// Ignore irrelevant files
if (
filename.endsWith('.mdx') ||
filename.endsWith('.new.stories.tsx') ||
filename.endsWith('.spec.ts') ||
filename.includes('e2e')
) {
return;
}
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved

// Stop all processes if a file changes to prevent multiple builds at once
await stopAllProcesses();
console.log(chalk.cyanBright(`📂 File changed: ${filename}`));
Expand Down
4 changes: 3 additions & 1 deletion packages/atomic/scripts/generate-component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ async function generateFiles(name, outputDir) {
);
const resolvedOutputDir = path.resolve(outputDir);
const namePascalCase = kebabToPascal(name);
const shorterName = name.replace(/^atomic-/, '').toLowerCase();
const shorterName = namePascalCase
.replace(/^Atomic/, '')
.replace(/^./, (c) => c.toLowerCase());
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved

const files = [
{template: 'component.ts.hbs', output: `${name}.ts`},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
describe('AtomicCommerceSearchBox', () => {
describe('with instant products & suggestions', () => {
describe('when using keyboard navigation', () => {
test('should be able to navigate from the suggestions to the instant results and vice-versa', async () => {});
test('should execute the search after pressing "Enter" on a suggestion', async () => {});
test('should redirect to the result page after pressing "Enter" on an instant result', async () => {});
describe('and then switching to mouse and hovering a new suggestion', () => {
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
test('should execute the search reflected in the search box', () => {});
});
});

describe('when typing and then hovering a suggestion', () => {
test('should execute the search reflected in the search box', () => {});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,7 @@ export class AtomicCommerceSearchBox

private onSubmit() {
this.isExpanded = false;
if (
this.suggestionManager.isRightPanelInFocus() ||
this.suggestionManager.activeDescendantElement?.part.contains(
'recent-query-title-item'
)
) {
if (this.suggestionManager.keyboardActiveDescendant) {
this.suggestionManager.onSubmit();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ test.describe('with instant results & query suggestions', () => {
});
});
});

test.describe('when hovering a instant result and pressing Enter', () => {
test('should not redirect to the instant product url', async ({
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
searchBox,
}) => {
await searchBox.searchInput.click();
await searchBox.instantResult({listSide: 'Right'}).first().hover();
await searchBox.searchInput.press('Enter');
await expect(searchBox.searchInput).toHaveValue('');
});
});
});

test.describe('with disable-search=true and minimum-query-length=1', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
describe('AtomicCommerceSearchBoxInstantProducts', () => {
describe('when clicking', () => {
test('on a instant product, it should redirect to the product page', async () => {});
test('on the "See all products" button, it should execute the proper search', async () => {});
});

describe('when using keyboard navigation', () => {
test('on instant products, it should redirect to the product page', async () => {});
test('on the "See all products" button, it should execute the proper search', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new product', () => {
test('it should execute the search reflected in the search box', () => {});
});

// This is a bug currently in the component
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
describe('when using the "See all products" button', () => {
test('it should reflect the query in the search box', async () => {});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
describe('AtomicCommerceSearchBoxQuerySuggestions', () => {
describe('when clicking', () => {
test('it should execute the proper search', async () => {});
});

describe('when using keyboard navigation', () => {
test('it should reflect the proper suggestion in the search box', async () => {});
test('it should execute the proper search after pressing "Enter"', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new suggestion', () => {
test('it should execute the search reflected in the search box', () => {});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
describe('AtomicCommerceSearchBoxRecentQueries', () => {
describe('when clicking', () => {
test('on a recent query, it should execute the proper search', async () => {});
test('on the "Clear" button, it should clear the recent queries', async () => {});
});

describe('when using keyboard navigation', () => {
test('on recent queries, it should reflect the proper query in the search box', async () => {});
test('on recent queries, it should execute the proper search', async () => {});
test('on the "Clear" button, it should clear the recent queries ', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new recent query', () => {
test('it should execute the search reflected in the search box', () => {});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class SuggestionManager<SearchBoxController> {
public triggerSuggestions: () => Promise<void>;
public activeDescendant = '';
public suggestedQuery = '';
public keyboardActiveDescendant = '';

private queryDataAttribute = 'data-query';
private suggestionEvents: SearchBoxSuggestionsEvent<SearchBoxController>[] =
Expand Down Expand Up @@ -114,6 +115,10 @@ export class SuggestionManager<SearchBoxController> {
forceUpdate(this.ownerSearchBoxProps.getHost());
}

public updateKeyboardActiveDescendant(id = '') {
this.keyboardActiveDescendant = id;
}

public clickOnActiveElement() {
this.activeDescendantElement?.click();
this.updateActiveDescendant();
Expand Down Expand Up @@ -187,6 +192,7 @@ export class SuggestionManager<SearchBoxController> {
}

public focusValue(value: HTMLElement) {
this.updateKeyboardActiveDescendant(value.id);
this.updateActiveDescendant(value.id);
this.scrollActiveDescendantIntoView();
this.updateQueryFromSuggestion();
Expand All @@ -198,6 +204,8 @@ export class SuggestionManager<SearchBoxController> {
id: string
) {
const thisPanel = side === 'left' ? this.leftPanel : this.rightPanel;
// When hovering, always reset the keyboard active descendant
this.updateKeyboardActiveDescendant();
if (this.panelInFocus === thisPanel) {
this.updateActiveDescendant(id);
} else {
Expand Down Expand Up @@ -226,6 +234,7 @@ export class SuggestionManager<SearchBoxController> {

public focusPreviousValue() {
if (this.firstValue === this.activeDescendantElement) {
this.updateKeyboardActiveDescendant();
this.updateActiveDescendant();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
describe('AtomicSearchBox', () => {
describe('with instant results & suggestions', () => {
describe('when using keyboard navigation', () => {
test('should be able to navigate from the suggestions to the instant results and vice-versa', async () => {});
test('should execute the search after pressing "Enter" on a suggestion', async () => {});
test('should redirect to the result page after pressing "Enter" on an instant result', async () => {});
describe('and then switching to mouse and hovering a new suggestion', () => {
test('should execute the search reflected in the search box', () => {});
});
});

describe('when typing and then hovering a suggestion', () => {
test('should execute the search reflected in the search box', () => {});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,7 @@ export class AtomicSearchBox implements InitializableComponent<Bindings> {

private onSubmit() {
this.isExpanded = false;
if (
this.suggestionManager.isRightPanelInFocus() ||
this.suggestionManager.activeDescendantElement?.part.contains(
'recent-query-title-item'
)
) {
if (this.suggestionManager.keyboardActiveDescendant) {
this.suggestionManager.onSubmit();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ test.describe('with instant results & query suggestions', () => {
});
});
});

test.describe('when hovering a instant result and pressing Enter', () => {
test('should not redirect to the instant result url', async ({
searchBox,
}) => {
await searchBox.searchInput.click();
await searchBox.instantResult({listSide: 'Right'}).first().hover();
await searchBox.searchInput.press('Enter');
await expect(searchBox.searchInput).toHaveValue('');
});
});
});

test.describe('with disable-search=true and minimum-query-length=1', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
describe('AtomicSearchBoxInstantResults', () => {
describe('when clicking', () => {
test('on a instant result, it should redirect to the result page', async () => {});
test('on the "See all results" button, it should execute the proper search', async () => {});
});

describe('when using keyboard navigation', () => {
test('on instant results, it should redirect to the result page', async () => {});
test('on the "See all results" button, it should execute the proper search', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new result', () => {
test('it should execute the search reflected in the search box', () => {});
});

// This is a bug currently in the component
describe('when using the "See all results" button', () => {
test('it should reflect the query in the search box', async () => {});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
describe('AtomicSearchBoxQuerySuggestions', () => {
describe('when clicking', () => {
test('it should execute the proper search', async () => {});
});

describe('when using keyboard navigation', () => {
test('it should reflect the proper suggestion in the search box', async () => {});
test('it should execute the proper search after pressing "Enter"', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new suggestion', () => {
test('it should execute the search reflected in the search box', () => {});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {describe, test} from 'vitest';

//TODO: Write those tests during the lit migration
describe('AtomicSearchBoxRecentQueries', () => {
describe('when clicking', () => {
test('on a recent query, it should execute the proper search', async () => {});
test('on the "Clear" button, it should clear the recent queries', async () => {});
});

describe('when using keyboard navigation', () => {
test('on recent queries, it should reflect the proper query in the search box', async () => {});
test('on recent queries, it should execute the proper search', async () => {});
test('on the "Clear" button, it should clear the recent queries ', async () => {});
});

describe('when using keyboard navigation and then switching to mouse and hovering a new recent query', () => {
test('it should execute the search reflected in the search box', () => {});
});
});
Loading