Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
style(ui): dropdown/ctx menu selection style, focus first item on open (#5525)
Seamus85803254c178
diff --git a/apps/web/src/components/ui/components/Dropdown.tsx b/apps/web/src/components/ui/components/Dropdown.tsxindex 3659815456..cb918ee7ef 100644--- a/apps/web/src/components/ui/components/Dropdown.tsx+++ b/apps/web/src/components/ui/components/Dropdown.tsx@@ -3,7 +3,10 @@ import { DropdownMenu as KobalteDropdownMenu } from '@kobalte/core/dropdown-menuimport CheckIcon from '@phosphor/check.svg';import { type ComponentProps, onCleanup, splitProps } from 'solid-js';import { cn } from '../utils/classname';-import { addCtrlJKMenuNavigation } from '../utils/menuKeyboardNavigation';+import {+ addCtrlJKMenuNavigation,+ highlightFirstMenuItemOnOpen,+} from '../utils/menuKeyboardNavigation';import { Button, type ButtonProps } from './Button';import { Surface, type SurfaceProps } from './Surface';@@ -166,6 +169,7 @@ function callRef<T>(ref: ((el: T) => void) | undefined, el: T) {function DropdownContent(props: DropdownContentProps) {let searchRef: HTMLDivElement | undefined;+ let contentRef: HTMLElement | undefined;const [local, rest] = splitProps(props, ['depth','class',@@ -173,10 +177,18 @@ function DropdownContent(props: DropdownContentProps) {'portalScope','children','ref',+ 'onOpenAutoFocus',]);+ const handleOpenAutoFocus = (event: Event) => {+ local.onOpenAutoFocus?.(event);+ if (!event.defaultPrevented && contentRef) {+ highlightFirstMenuItemOnOpen(contentRef);+ }+ };const setContentRef = (el: HTMLElement) => {installKeyboardNavigation(el);installSwipeToDismiss(el);+ contentRef = el;callRef(local.ref, el);};@@ -194,6 +206,7 @@ function DropdownContent(props: DropdownContentProps) {depth={local.depth ?? 2}as={Surface}{...rest}+ onOpenAutoFocus={handleOpenAutoFocus}ref={setContentRef}><div class="flex flex-col gap-(--app-border-width) bg-edge-muted size-full">@@ -272,8 +285,7 @@ function DropdownGroupLabel(props: DropdownGroupLabelProps) {const CHECKBOX_ITEM_BOX_CLASS = cn('inline-flex items-center justify-center size-3.5 shrink-0 rounded-sm','border border-transparent text-surface',- 'group-data-highlighted:not-hover:border-edge-muted',- 'hover:border-accent',+ 'group-data-highlighted:border-edge-muted','group-data-checked:bg-accent group-data-checked:border-accent');diff --git a/apps/web/src/components/ui/index.ts b/apps/web/src/components/ui/index.tsindex d3276f1679..9aab75675c 100644--- a/apps/web/src/components/ui/index.ts+++ b/apps/web/src/components/ui/index.ts@@ -77,5 +77,6 @@ export {addCtrlJKMenuNavigation,ctrlJKMenuNavigation,handleCtrlJKMenuNavigation,+ highlightFirstMenuItemOnOpen,wrapIndex,} from './utils/menuKeyboardNavigation';diff --git a/apps/web/src/components/ui/utils/menuKeyboardNavigation.ts b/apps/web/src/components/ui/utils/menuKeyboardNavigation.tsindex 86ffd415ea..a325b3604e 100644--- a/apps/web/src/components/ui/utils/menuKeyboardNavigation.ts+++ b/apps/web/src/components/ui/utils/menuKeyboardNavigation.ts@@ -25,6 +25,31 @@ export type CtrlJKMenuNavigationOptions = {const NAVIGABLE_ITEM_SELECTOR ='[role="option"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]';+export function highlightFirstMenuItemOnOpen(el: HTMLElement) {+ setTimeout(() => {+ requestAnimationFrame(() => {+ if (!el.isConnected || el.querySelector('[data-highlighted]')) return;++ const activeElement = document.activeElement;+ if (activeElement && activeElement !== el && el.contains(activeElement)) {+ return;+ }++ if (!el.querySelector(NAVIGABLE_ITEM_SELECTOR)) return;++ el.dispatchEvent(+ new KeyboardEvent('keydown', {+ key: 'ArrowDown',+ code: 'ArrowDown',+ bubbles: true,+ cancelable: true,+ composed: true,+ })+ );+ });+ }, 0);+}+declare module 'solid-js' {namespace JSX {interface Directives {diff --git a/apps/web/src/lib/core/component/ContextMenu.tsx b/apps/web/src/lib/core/component/ContextMenu.tsxindex 89647e5396..66c77d1b4f 100644--- a/apps/web/src/lib/core/component/ContextMenu.tsx+++ b/apps/web/src/lib/core/component/ContextMenu.tsx@@ -3,7 +3,12 @@ import { isMobile } from '@core/mobile/isMobile';import { ContextMenu } from '@kobalte/core/context-menu';import CaretRight from '@phosphor/caret-right.svg?component-solid';import CheckIcon from '@phosphor/check.svg?component-solid';-import { addCtrlJKMenuNavigation, cn, Layer } from '@ui';+import {+ addCtrlJKMenuNavigation,+ cn,+ highlightFirstMenuItemOnOpen,+ Layer,+} from '@ui';import { Hotkey } from '@ui/components/Hotkey';import {type Component,@@ -399,6 +404,13 @@ export function ContextMenuContent(props: ParentProps<MenuContentProps>) {onCleanup(cleanup);});+ const handleOpenAutoFocus = (event: Event) => {+ props.onOpenAutoFocus?.(event);+ if (!event.defaultPrevented && contentRef) {+ highlightFirstMenuItemOnOpen(contentRef);+ }+ };+return (<MobileConditionalOverlay mobileFullScreen={props.mobileFullScreen}><Show@@ -415,7 +427,7 @@ export function ContextMenuContent(props: ParentProps<MenuContentProps>) {isMobile() &&'flex flex-col justify-center px-4 max-h-[80vh] shrink w-[calc(100vw-1rem)]')}- onOpenAutoFocus={props.onOpenAutoFocus}+ onOpenAutoFocus={handleOpenAutoFocus}ref={contentRef}onCloseAutoFocus={props.onCloseAutoFocus}>