App menu: one home in the titlebar, the logo
The top-right ⋮ and the logo opened the same menu: one of them was redundant. The logo stays as the only titlebar trigger (the app's own mark, where an app menu lives); the right side is back to workspaces, accounts and the window buttons. Alt+F, F10, the palette and the account menu's last row open the menu under the logo. Apps that want a separate button keep <AppMenu/>'s default trigger.
This commit is contained in:
parent
7d7283fa01
commit
b7b2efe868
2 changed files with 12 additions and 7 deletions
|
|
@ -69,7 +69,7 @@ function stopsOf(menu: HTMLElement): HTMLElement[] {
|
||||||
return all.filter(el => !('zoom' in el.dataset) || el === keep);
|
return all.filter(el => !('zoom' in el.dataset) || el === keep);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AppMenu() {
|
export function AppMenu({ trigger = true }: { trigger?: boolean } = {}) {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
usePaneTick();
|
usePaneTick();
|
||||||
const dev = useDev();
|
const dev = useDev();
|
||||||
|
|
@ -107,9 +107,13 @@ export function AppMenu() {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/** Where a request without an anchor opens: the button when this app shows one, else the logo. */
|
||||||
|
const home = (): Anchor['at'] => (trigger ? 'button' : 'logo');
|
||||||
|
|
||||||
function show(request: AppMenuRequest = {}) {
|
function show(request: AppMenuRequest = {}) {
|
||||||
diag(`menu open: anchor=${request.anchor ?? 'button'} keyboard=${!!request.keyboard} hasFocus=${document.hasFocus()} active=${describe(document.activeElement)}`);
|
const at = request.anchor ?? home();
|
||||||
const logo = request.anchor === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
|
diag(`menu open: anchor=${at} keyboard=${!!request.keyboard} hasFocus=${document.hasFocus()} active=${describe(document.activeElement)}`);
|
||||||
|
const logo = at === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
|
||||||
const rect = (logo ?? button.current)?.getBoundingClientRect();
|
const rect = (logo ?? button.current)?.getBoundingClientRect();
|
||||||
if (rect) {
|
if (rect) {
|
||||||
const top = Math.round(rect.bottom + 6);
|
const top = Math.round(rect.bottom + 6);
|
||||||
|
|
@ -162,7 +166,7 @@ export function AppMenu() {
|
||||||
const onRequest = (event: Event) => {
|
const onRequest = (event: Event) => {
|
||||||
const request = (event as CustomEvent<AppMenuRequest | undefined>).detail ?? {};
|
const request = (event as CustomEvent<AppMenuRequest | undefined>).detail ?? {};
|
||||||
// Asked again from the other trigger, the open menu moves there instead of closing.
|
// Asked again from the other trigger, the open menu moves there instead of closing.
|
||||||
if (live.current.open && request.toggle && (request.anchor ?? 'button') === (openAt ?? 'button')) close('escape'); else show(request);
|
if (live.current.open && request.toggle && (request.anchor ?? home()) === (openAt ?? home())) close('escape'); else show(request);
|
||||||
};
|
};
|
||||||
window.addEventListener('bt-app-menu', onRequest);
|
window.addEventListener('bt-app-menu', onRequest);
|
||||||
return () => window.removeEventListener('bt-app-menu', onRequest);
|
return () => window.removeEventListener('bt-app-menu', onRequest);
|
||||||
|
|
@ -559,10 +563,10 @@ export function AppMenu() {
|
||||||
|
|
||||||
const label = menuText('label');
|
const label = menuText('label');
|
||||||
return <>
|
return <>
|
||||||
<button ref={button} type="button" className="bt-app-button" aria-haspopup="menu" aria-expanded={open && anchor.at === 'button'} aria-label={label} title={`${label} (${APP_MENU_KEYS})`}
|
{trigger && <button ref={button} type="button" className="bt-app-button" aria-haspopup="menu" aria-expanded={open && anchor.at === 'button'} aria-label={label} title={`${label} (${APP_MENU_KEYS})`}
|
||||||
onClick={event => (open && anchor.at === 'button' ? close('escape') : show({ keyboard: event.detail === 0 }))}>
|
onClick={event => (open && anchor.at === 'button' ? close('escape') : show({ keyboard: event.detail === 0 }))}>
|
||||||
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="5.75" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="18.25" r="1.6"/></svg>
|
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="5.75" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="18.25" r="1.6"/></svg>
|
||||||
</button>
|
</button>}
|
||||||
{open && createPortal(<div className="bt-menu-backdrop" onMouseDown={() => close()} onContextMenu={event => { event.preventDefault(); close(); }}>
|
{open && createPortal(<div className="bt-menu-backdrop" onMouseDown={() => close()} onContextMenu={event => { event.preventDefault(); close(); }}>
|
||||||
<div ref={layers} className="bt-app-layers" onMouseDown={event => event.stopPropagation()} onContextMenu={event => { event.preventDefault(); event.stopPropagation(); }} onKeyDown={onKey}>
|
<div ref={layers} className="bt-app-layers" onMouseDown={event => event.stopPropagation()} onContextMenu={event => { event.preventDefault(); event.stopPropagation(); }} onKeyDown={onKey}>
|
||||||
{renderMenus()}
|
{renderMenus()}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ export function Titlebar({ maximized }: { maximized: boolean }) {
|
||||||
<TitlebarExtras/>
|
<TitlebarExtras/>
|
||||||
<AccountSwitcher/>
|
<AccountSwitcher/>
|
||||||
<UpdateChip/>
|
<UpdateChip/>
|
||||||
<AppMenu/>
|
{/* One home for the app menu: the logo. Alt+F, F10, the palette and the account menu's last row open it there. */}
|
||||||
|
<AppMenu trigger={false}/>
|
||||||
{os !== 'macos' && <WindowControls maximized={maximized}/>}
|
{os !== 'macos' && <WindowControls maximized={maximized}/>}
|
||||||
</header>;
|
</header>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue