mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 14:01:16 -07:00
Tweak: handle QL selection without hover (#7105)
Release Drafter / Auto Label PR (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
This commit is contained in:
@@ -124,8 +124,8 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
? MOBILE_BUTTON_POSITIONS[settings.quicklaunch.mobileButtonPosition]
|
? MOBILE_BUTTON_POSITIONS[settings.quicklaunch.mobileButtonPosition]
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
function openCurrentItem(newWindow) {
|
function openCurrentItem(newWindow, index = activeItemIndex) {
|
||||||
const result = results[activeItemIndex];
|
const result = results[index];
|
||||||
window.open(
|
window.open(
|
||||||
result.href,
|
result.href,
|
||||||
newWindow ? "_blank" : (result.target ?? searchProvider?.target ?? settings.target ?? "_blank"),
|
newWindow ? "_blank" : (result.target ?? searchProvider?.target ?? settings.target ?? "_blank"),
|
||||||
@@ -180,7 +180,8 @@ export default function QuickLaunch({ servicesAndBookmarks, searchString, setSea
|
|||||||
|
|
||||||
function handleItemClick(event) {
|
function handleItemClick(event) {
|
||||||
closeAndReset();
|
closeAndReset();
|
||||||
openCurrentItem(event.metaKey);
|
// in case hover doesnt fire, use the clicked item, not the highlighted one
|
||||||
|
openCurrentItem(event.metaKey, parseInt(event.currentTarget.dataset.index, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleItemKeyDown(event) {
|
function handleItemKeyDown(event) {
|
||||||
|
|||||||
@@ -263,6 +263,37 @@ describe("components/quicklaunch", () => {
|
|||||||
openSpy.mockRestore();
|
openSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("opens the clicked result even without a preceding hover event", async () => {
|
||||||
|
const openSpy = vi.spyOn(window, "open").mockImplementation(() => null);
|
||||||
|
|
||||||
|
renderWithProviders(
|
||||||
|
<Wrapper
|
||||||
|
servicesAndBookmarks={[
|
||||||
|
{ name: "Alpha", href: "https://alpha.example" },
|
||||||
|
{ name: "Alpine", href: "https://alpine.example" },
|
||||||
|
{ name: "Almond", href: "https://almond.example" },
|
||||||
|
]}
|
||||||
|
/>,
|
||||||
|
{ settings: { target: "_self", quicklaunch: { showSearchSuggestions: false } } },
|
||||||
|
);
|
||||||
|
|
||||||
|
const input = screen.getByPlaceholderText("Search");
|
||||||
|
await waitFor(() => expect(input).toHaveFocus());
|
||||||
|
|
||||||
|
fireEvent.change(input, { target: { value: "al" } });
|
||||||
|
await waitFor(() => expect(document.querySelector('button[data-index="2"]')).toBeTruthy());
|
||||||
|
|
||||||
|
// touch devices don't fire mouseEnter, so the highlighted item is still the first one
|
||||||
|
fireEvent.click(document.querySelector('button[data-index="2"]'));
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await new Promise((r) => setTimeout(r, 350));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(openSpy).toHaveBeenCalledWith("https://almond.example", "_self", "noreferrer");
|
||||||
|
openSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
it("handles Escape on a result button (not just the input)", async () => {
|
it("handles Escape on a result button (not just the input)", async () => {
|
||||||
renderWithProviders(<Wrapper servicesAndBookmarks={[{ name: "Alpha", href: "https://alpha.example" }]} />, {
|
renderWithProviders(<Wrapper servicesAndBookmarks={[{ name: "Alpha", href: "https://alpha.example" }]} />, {
|
||||||
settings: { quicklaunch: { showSearchSuggestions: false } },
|
settings: { quicklaunch: { showSearchSuggestions: false } },
|
||||||
|
|||||||
Reference in New Issue
Block a user