mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-23 06:10:32 +00:00
## Summary Allow asset/media FormDropdown searches to select the top filtered result when the user presses Enter. This covers image, video, audio, mesh, model-like asset selects, and other `WidgetSelectDropdown`-backed media widgets. ## Implementation Scope This PR implements a **top-result Enter shortcut** for the custom asset/media dropdown path only: - In scope: `WidgetSelectDropdown` -> `FormDropdown` asset/media widgets. - In scope: while the dropdown is open, single-select, and the search text is non-empty, the first current search result becomes the Enter candidate. - In scope: pressing Enter in the search input selects that candidate/top result through the existing selection path. - In scope: candidate feedback for this shortcut, including visual candidate styling and a polite screen-reader announcement for the current top result. - In scope: stale async search protection, empty-query/no-result no-op behavior, multi-select guard behavior, and focus return to the trigger after Enter selection closes the menu. - Out of scope: plain combo widgets (`WidgetSelectDefault` / `SelectPlus`). That path is PrimeVue-based and should be handled separately from this focused asset-widget PR. - Out of scope: full combobox/listbox keyboard navigation, including Tab-to-list focus, ArrowUp/ArrowDown candidate movement, Home/End behavior, scroll-to-active-item behavior, and a full ARIA combobox/listbox refactor. Follow-up arrow-key navigation should validate the interaction model separately. This PR keeps the candidate state narrow and localized so that future work can either extend it into movable active-item state or replace it as part of a fuller combobox/listbox implementation. ## Changes - **What**: Added an explicit Enter event from `FormSearchInput`, routed it through the FormDropdown menu actions, and selected the current top search result in `FormDropdown`. - **What**: Kept the existing `computedAsync` + debounced filtering path for normal typing, while Enter performs a one-off search against the latest input before selecting. Stale async Enter results are ignored if the query or item source changes before resolution. - **What**: Prevented closed FormDropdown state from treating the full unfiltered list as current search results, limited Enter-to-select to single-select dropdowns, and made empty search Enter a no-op. - **What**: Returned focus to the dropdown trigger after single-select selection closes the menu. - **What**: Added candidate styling for the first current FormDropdown result while a search query is active so the Enter target is visible to users. - **What**: Added a polite screen-reader announcement for the current top result candidate. - **What**: Fixed the FormDropdownMenuActions `baseModelSelected` model default to use a `Set` factory instead of a shared instance. - **What**: Added unit coverage for the search Enter event, FormDropdown selection behavior, focus return, debounce/Enter behavior, stale async Enter protection, empty-query no-op behavior, closed-state stale result protection, multi-select guard behavior, and candidate announcement behavior. Added App Mode E2E coverage for asset FormDropdown Enter selection. - **What**: Extracted reusable app-mode dropdown fixture helpers and updated the existing FormDropdown clipping test to use the shared helper. ## Review Focus Please focus review on the asset/media FormDropdown path, especially `getTopSearchResult()`, the single-select/empty-query guards, stale async search protection, trigger focus return after selection, and candidate feedback in grid/list layouts. The plain combo path and full arrow-key navigation are intentionally left for separate follow-up work. ## Screenshots (if applicable) https://github.com/user-attachments/assets/3eb3456d-93a3-4959-91a3-188f8116ccc9 Validation performed: - Latest final-commit validation: - `pnpm test:unit src/renderer/extensions/vueNodes/widgets/components/form/FormSearchInput.test.ts src/renderer/extensions/vueNodes/widgets/components/form/dropdown/FormDropdown.test.ts src/renderer/extensions/vueNodes/widgets/components/form/dropdown/FormDropdownMenuActions.test.ts src/renderer/extensions/vueNodes/widgets/components/form/dropdown/FormDropdownMenu.test.ts` - Commit hook: `pnpm exec stylelint ...`, `pnpm exec oxfmt --write ...`, `pnpm exec oxlint --type-aware --fix ...`, `pnpm exec eslint --cache --fix ...`, `pnpm typecheck` - Push hook: `pnpm knip --cache` - `git diff --check` - Earlier branch validation for this flow: - `pnpm install` - `pnpm typecheck:browser` - `PLAYWRIGHT_LOCAL=1 PLAYWRIGHT_TEST_URL=http://localhost:5173 PLAYWRIGHT_SETUP_API_URL=http://localhost:8188 pnpm test:browser -- --project=chromium browser_tests/tests/appMode.spec.ts -g "Drag and Drop|FormDropdown search Enter selects the top filtered item" --reporter=list` - `PLAYWRIGHT_LOCAL=1 PLAYWRIGHT_TEST_URL=http://localhost:5173 PLAYWRIGHT_SETUP_API_URL=http://localhost:8188 pnpm test:browser -- --project=chromium browser_tests/tests/appMode.spec.ts -g "FormDropdown search Enter selects the top filtered item" --reporter=list` - `PLAYWRIGHT_LOCAL=1 PLAYWRIGHT_TEST_URL=http://localhost:5173 PLAYWRIGHT_SETUP_API_URL=http://localhost:8188 pnpm test:browser -- --project=chromium browser_tests/tests/appModeDropdownClipping.spec.ts -g "FormDropdown popup is not clipped" --reporter=list`
100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
import type { Locator, Page } from '@playwright/test'
|
|
|
|
import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
|
|
import { WidgetSelectDropdownFixture } from '@e2e/fixtures/components/WidgetSelectDropdown'
|
|
|
|
/**
|
|
* Helper for interacting with widgets rendered in app mode (linear view).
|
|
*
|
|
* Widgets are located by their key (format: "nodeId:widgetName") via the
|
|
* `data-widget-key` attribute on each widget item.
|
|
*/
|
|
export class AppModeWidgetHelper {
|
|
constructor(private readonly comfyPage: ComfyPage) {}
|
|
|
|
private get page(): Page {
|
|
return this.comfyPage.page
|
|
}
|
|
|
|
private get container(): Locator {
|
|
return this.comfyPage.appMode.linearWidgets
|
|
}
|
|
|
|
/** Get a widget item container by its key (e.g. "6:text", "3:seed"). */
|
|
getWidgetItem(key: string): Locator {
|
|
return this.container.locator(`[data-widget-key="${key}"]`)
|
|
}
|
|
|
|
/** Get a FormDropdown widget by its key (e.g. "10:image"). */
|
|
getSelectDropdown(key: string): WidgetSelectDropdownFixture {
|
|
return new WidgetSelectDropdownFixture(this.getWidgetItem(key))
|
|
}
|
|
|
|
/** Fill a textarea widget (e.g. CLIP Text Encode prompt). */
|
|
async fillTextarea(key: string, value: string) {
|
|
const widget = this.getWidgetItem(key)
|
|
await widget.locator('textarea').fill(value)
|
|
}
|
|
|
|
/**
|
|
* Set a number input widget value (INT or FLOAT).
|
|
* Targets the last input inside the widget — this works for both
|
|
* ScrubableNumberInput (single input) and slider+InputNumber combos
|
|
* (last input is the editable number field).
|
|
*/
|
|
async fillNumber(key: string, value: string) {
|
|
const widget = this.getWidgetItem(key)
|
|
const input = widget.locator('input').last()
|
|
await input.fill(value)
|
|
await input.press('Enter')
|
|
}
|
|
|
|
/** Fill a string text input widget (e.g. filename_prefix). */
|
|
async fillText(key: string, value: string) {
|
|
const widget = this.getWidgetItem(key)
|
|
await widget.locator('input').fill(value)
|
|
}
|
|
|
|
/** Select an option from a combo/select widget. */
|
|
async selectOption(key: string, optionName: string) {
|
|
const widget = this.getWidgetItem(key)
|
|
await widget.getByRole('combobox').click()
|
|
await this.page
|
|
.getByRole('option', { name: optionName, exact: true })
|
|
.click()
|
|
}
|
|
|
|
/**
|
|
* Intercept the /api/prompt POST, click Run, and return the prompt payload.
|
|
* Fulfills the route with a mock success response.
|
|
*/
|
|
async runAndCapturePrompt(): Promise<
|
|
Record<string, { inputs: Record<string, unknown> }>
|
|
> {
|
|
let promptBody: Record<string, { inputs: Record<string, unknown> }> | null =
|
|
null
|
|
await this.page.route(
|
|
'**/api/prompt',
|
|
async (route, req) => {
|
|
promptBody = req.postDataJSON().prompt
|
|
await route.fulfill({
|
|
status: 200,
|
|
body: JSON.stringify({
|
|
prompt_id: 'test-id',
|
|
number: 1,
|
|
node_errors: {}
|
|
})
|
|
})
|
|
},
|
|
{ times: 1 }
|
|
)
|
|
|
|
const responsePromise = this.page.waitForResponse('**/api/prompt')
|
|
await this.comfyPage.appMode.runButton.click()
|
|
await responsePromise
|
|
|
|
if (!promptBody) throw new Error('No prompt payload captured')
|
|
return promptBody
|
|
}
|
|
}
|