Skip to content

Commit 37a1db4

Browse files
fusharclaude
andcommitted
Omnibar: add pressed state for the Help and Notifications buttons
Introduce an `isActive` flag on `OmnibarNode` and render leaf nodes with `is-active` plus `aria-pressed`, then wire the help center and notifications plugins to it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3b0bc8d commit 37a1db4

6 files changed

Lines changed: 12 additions & 2 deletions

File tree

client/dashboard/app/omnibar/plugin-help-center.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function useHelpCenterPlugin(): OmnibarNode {
2828
id: 'help-center',
2929
label: __( 'Help' ),
3030
icon: <HelpIcon />,
31+
isActive: isHelpCenterShown,
3132
onClick: () => setShowHelpCenter( ! isHelpCenterShown ),
3233
};
3334
}

client/dashboard/app/omnibar/plugin-notifications.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
.omnibar .omnibar__menu:hover .omnibar__notifications-unread-dot,
2525
.omnibar .omnibar__menu:focus-visible .omnibar__notifications-unread-dot,
26-
.omnibar .omnibar__menu:active .omnibar__notifications-unread-dot {
26+
.omnibar .omnibar__menu:active .omnibar__notifications-unread-dot,
27+
.omnibar .omnibar__menu.is-active .omnibar__notifications-unread-dot {
2728
stroke: var( --omnibar-menu-active-background );
2829
}

client/dashboard/app/omnibar/plugin-notifications.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ export function useNotificationsPlugin( { user }: { user?: User } ): OmnibarNode
2121
const [ hasUnseenNotifications, setHasUnseenNotifications ] = useState(
2222
!! user?.has_unseen_notes
2323
);
24+
const [ isPanelOpen, setIsPanelOpen ] = useState( false );
2425

2526
useOmnibarEvent( 'notificationsUnseenCount', ( count ) =>
2627
setHasUnseenNotifications( count > 0 )
2728
);
2829

30+
useOmnibarEvent( 'notificationsOpen', setIsPanelOpen );
31+
2932
const bellRef = useRef< HTMLSpanElement >( null );
3033

3134
// Re-runs every commit so the anchor stays correct if the bell button is replaced.
@@ -41,6 +44,7 @@ export function useNotificationsPlugin( { user }: { user?: User } ): OmnibarNode
4144
<BellIcon hasUnread={ hasUnseenNotifications } />
4245
</span>
4346
),
47+
isActive: isPanelOpen,
4448
onClick: () => omnibarEvents.notifications.emit(),
4549
};
4650
}

packages/omnibar/src/components/omnibar-menu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ function OmnibarMenuContent( { nodes }: { nodes: OmnibarNode[] } ) {
6767

6868
export function OmnibarMenu( { node, className }: { node: OmnibarNode; className?: string } ) {
6969
const label = node.title || node.label || '';
70-
const menuClassName = className ? `omnibar__menu ${ className }` : 'omnibar__menu';
70+
const classNames = [ 'omnibar__menu', className, node.isActive && 'is-active' ].filter( Boolean );
71+
const menuClassName = classNames.join( ' ' );
7172
const [ isOpen, setIsOpen ] = useState( false );
7273
const triggerRef = useRef< HTMLElement >( null );
7374
const popoverRef = useRef< HTMLElement >( null );
@@ -82,6 +83,7 @@ export function OmnibarMenu( { node, className }: { node: OmnibarNode; className
8283
nativeButton={ ! node.href }
8384
onClick={ node.onClick }
8485
aria-label={ label }
86+
aria-pressed={ node.href ? undefined : node.isActive }
8587
>
8688
<OmnibarNodeContent node={ node } />
8789
</Button>

packages/omnibar/src/components/omnibar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ body:has( .omnibar ) {
5656
&:hover,
5757
&:focus-visible,
5858
&:active,
59+
&.is-active,
5960
&[aria-expanded='true'] {
6061
background-color: var( --omnibar-menu-active-background );
6162
color: $omnibar-text-color;

packages/omnibar/src/types/omnibar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface OmnibarNode {
66
group?: boolean;
77
href?: string;
88
onClick?: () => void;
9+
isActive?: boolean;
910
meta?: SiteActionNodeMeta & UserInfoNodeMeta;
1011
render?: ( node: OmnibarNode ) => React.ReactNode;
1112
children?: OmnibarNode[];

0 commit comments

Comments
 (0)