fix(nx-dev): add data-document attribute to improve search (#30524)

This commit is contained in:
Nicholas Cunningham 2025-03-27 15:19:07 -06:00 committed by GitHub
parent d194248f53
commit 4a3a8241c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 8 deletions

View File

@ -18,7 +18,9 @@ export function Layout({
}} }}
/> />
</div> </div>
<main className="py-24 sm:py-32">{children}</main> <main className="py-24 sm:py-32" data-document="main">
{children}
</main>
</div> </div>
</div> </div>
); );

View File

@ -31,7 +31,10 @@ export function DefaultLayout({
}} }}
/> />
</div> </div>
<main className={isHome || hideHeader ? '' : 'py-24 sm:py-32'}> <main
data-document="main"
className={isHome || hideHeader ? '' : 'py-24 sm:py-32'}
>
{children} {children}
</main> </main>
</div> </div>

View File

@ -1,5 +1,5 @@
'use client'; 'use client';
import { Fragment, ReactElement } from 'react'; import { Fragment, type MouseEvent, ReactElement } from 'react';
import { NxCloudAnimatedIcon, NxIcon } from '@nx/nx-dev/ui-icons'; import { NxCloudAnimatedIcon, NxIcon } from '@nx/nx-dev/ui-icons';
import { import {
Bars3Icon, Bars3Icon,
@ -74,6 +74,11 @@ export function DocumentationHeader({
!isChangelog && !isChangelog &&
!isAiChat; !isAiChat;
const handleContextMenu = (e: MouseEvent) => {
e.preventDefault();
router.push('/brands');
};
const sections = [ const sections = [
{ name: 'Nx', href: '/getting-started/intro', current: isNx }, { name: 'Nx', href: '/getting-started/intro', current: isNx },
{ {
@ -217,8 +222,11 @@ export function DocumentationHeader({
href="/" href="/"
className="flex flex-grow items-center px-4 text-slate-900 lg:px-0 dark:text-white" className="flex flex-grow items-center px-4 text-slate-900 lg:px-0 dark:text-white"
prefetch={false} prefetch={false}
onContextMenu={handleContextMenu}
> >
<span className="sr-only">Nx</span> <span className="sr-only">
Nx Left-click: Home. Right-click: Brands.
</span>
<NxIcon aria-hidden="true" className="h-8 w-8" /> <NxIcon aria-hidden="true" className="h-8 w-8" />
</Link> </Link>
<Link <Link

View File

@ -17,13 +17,20 @@ import {
} from '@heroicons/react/24/outline'; } from '@heroicons/react/24/outline';
import cx from 'classnames'; import cx from 'classnames';
import Link from 'next/link'; import Link from 'next/link';
import { Fragment, ReactElement, useEffect, useState } from 'react'; import {
Fragment,
type MouseEvent,
ReactElement,
useEffect,
useState,
} from 'react';
import { ButtonLink, ButtonLinkProps } from '../button'; import { ButtonLink, ButtonLinkProps } from '../button';
import { resourceMenuItems } from './menu-items'; import { resourceMenuItems } from './menu-items';
import { MobileMenuItem } from './mobile-menu-item'; import { MobileMenuItem } from './mobile-menu-item';
import { SectionsMenu } from './sections-menu'; import { SectionsMenu } from './sections-menu';
import { AlgoliaSearch } from '@nx/nx-dev/feature-search'; import { AlgoliaSearch } from '@nx/nx-dev/feature-search';
import { GitHubIcon, NxIcon } from '@nx/nx-dev/ui-icons'; import { GitHubIcon, NxIcon } from '@nx/nx-dev/ui-icons';
import { useRouter } from 'next/navigation';
interface HeaderProps { interface HeaderProps {
ctaButtons?: ButtonLinkProps[]; ctaButtons?: ButtonLinkProps[];
@ -32,6 +39,13 @@ interface HeaderProps {
export function Header({ ctaButtons }: HeaderProps): ReactElement { export function Header({ ctaButtons }: HeaderProps): ReactElement {
let [isOpen, setIsOpen] = useState(false); let [isOpen, setIsOpen] = useState(false);
const router = useRouter();
const handleContextMenu = (e: MouseEvent) => {
e.preventDefault();
router.push('/brands');
};
// We need to close the popover if the route changes or the window is resized to prevent the popover from being stuck open. // We need to close the popover if the route changes or the window is resized to prevent the popover from being stuck open.
const checkSizeAndClosePopover = () => { const checkSizeAndClosePopover = () => {
const breakpoint = 1024; // This is the standard Tailwind lg breakpoint value const breakpoint = 1024; // This is the standard Tailwind lg breakpoint value
@ -78,8 +92,11 @@ export function Header({ ctaButtons }: HeaderProps): ReactElement {
href="/" href="/"
className="mr-4 flex items-center text-slate-900 dark:text-white" className="mr-4 flex items-center text-slate-900 dark:text-white"
prefetch={false} prefetch={false}
onContextMenu={handleContextMenu}
> >
<span className="sr-only">Nx</span> <span className="sr-only">
Nx Left-click: Home. Right-click: Brands.
</span>
<NxIcon aria-hidden="true" className="h-8 w-8" /> <NxIcon aria-hidden="true" className="h-8 w-8" />
</Link> </Link>
<nav <nav

View File

@ -21,7 +21,9 @@ export function Layout({
}} }}
/> />
</div> </div>
<main className="py-24 sm:py-32">{children}</main> <main className="py-24 sm:py-32" data-document="main">
{children}
</main>
</div> </div>
<Footer /> <Footer />
</div> </div>

View File

@ -7,7 +7,7 @@ export function EnterpriseLayout({
return ( return (
<div className="w-full dark:bg-slate-950"> <div className="w-full dark:bg-slate-950">
<Header /> <Header />
<main>{children}</main> <main data-document="main">{children}</main>
<Footer /> <Footer />
</div> </div>
); );