Repository navigation
feat(widget): add header menu with conversation and privacy options - #505
Conversation
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
anurag629
left a comment
There was a problem hiding this comment.
Thanks @anurag2787. Loading the menu as its own chunk with its own size entry is the right shape. With dev merged in, build, typecheck, api:check, docs:check and coverage pass. Some things need fixing first:
Tests that fail
- Your e2e test
header menu with keyboard navigation and New conversation(e2e/tests/states.spec.ts:257) fails in light, dark and RTL: afterEnterthe menu is still visible (line 275). RunE2E_CHANNEL=chrome pnpm e2e(orpnpm e2ewith Playwright's Chromium) before pushing. e2e/tests/loader.spec.ts:168fails: opening the panel now downloadschunks/menu-*.js, becausePanel.show()callsloadMenu(). Chunks load only when they're used (that test is the guard), so drop that line and load the menu on the button's click and keydown. Prefetching onpointerenter/focusof the button is fine if you want it.
Size
3. pnpm size fails: the panel goes from 17.34 to 18.37 kB and the single file to 21.45 kB. A menu in its own chunk should cost the panel a few hundred bytes, not 1 kB. Move what only the menu needs into menu.ts: the label defaults in renderHeader() (moreLabel = 'More options' and so on, which panelLabels() always passes anyway), the open and keyboard wiring, and the escaping. Then the panel only creates the button and calls loadMenu().
4. Please revert the single-file limit in .size-limit.json (20 to 22 kB). Budget changes go in their own PR so they're decided once; the issue asked to talk first. I'm opening one now to make room for this, #504 and #502, and you can update from dev after it.
Code
5. packages/widget/src/i18n.ts: remove the moreOptions alias in getWidgetLocale(). It's a second public name for moreButton that nothing asked for.
6. packages/widget/src/widget.ts, downloadTranscript(): make it private. As it is, it's public API (it shows in api/widget.api.md), and 1.0 freezes that.
7. Same function: URL.revokeObjectURL(a.href) right after a.click() can cancel the download in some browsers. Revoke it in a setTimeout(..., 0) or later.
8. packages/widget/src/styles/menu.css: .cc-menu-item:focus-visible sets outline: none with only a background change, which is too faint to count as a focus indicator. Use box-shadow: var(--cc-focus-ring) like the other controls (see the focus list at the end of widget.css).
Lint
9. Three new Biome warnings, noExplicitAny in packages/widget/tests/dom/menu.test.ts at 186, 199 and 222. Type widget with a small interface for what the test reads, as tests/stop.test.ts does with internals(). pnpm lint should say 38 warnings, the same as dev.
|
@anurag2787 #508 has raised the single-file limit to 22 kB and the panel to 19 kB, so drop your |
Signed-off-by: Anurag Yadav <anuragyadav2787@gmail.com>
anurag629
left a comment
There was a problem hiding this comment.
Thanks @anurag2787, all of it is addressed. With dev merged in:
- build, typecheck, lint (38),
api:check,docs:checkand coverage pass pnpm sizepasses: panel 18.26 of 19 kB, menu chunk 1.7 kB, single file 21.53 of 22 kB- all 85 e2e tests pass in Chrome, including the loader chunk check and your menu test
I also checked the first Enter, Space and click on the button, before the chunk has loaded, and each opens the menu once.
|
@anurag2787 approved and CI is green, but the PR is still a draft, so it can't be merged. Mark it ready for review when you're done with it and I'll merge. |
|
Hi @anurag629 i made the PR ready for review |
|
Merged, thanks @anurag2787. |
What does this change?
Added a More Options menu to the widget header with options to start a new conversation
Closes #496
How I tested this
Ran pnpm test:coverage, pnpm lint, pnpm api, pnpm docs:check and pnpm size. Verified menu interactions, keyboard navigation, transcript download, and privacy URL validation
AI assistance
ChatGPT was used to help with the implementation and tests
Checklist
devpnpm -r build,pnpm testandpnpm -r typecheckpass locallypnpm changeset) if this changescore,widgetorserverpnpm apirun andapi/committed if an exported type or option changed