Skip to content

Full-screen search in React

A search covering the page, with popular suggestions, opened from the navigation bar.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

FullScreenSearch.tsx
import { useId } from "react";
import { useDialog } from "./useDialog";

type FullScreenSearchProps = {
  popular: { label: string; href: string }[];
  onSearch: (query: string) => void;
};

export function FullScreenSearch({ popular, onSearch }: FullScreenSearchProps) {
  const dialog = useDialog();
  const id = useId();
  return (
useDialog.ts
import { useCallback, useEffect, useRef, useState } from "react";

/**
 * Drives a native <dialog>: the browser handles the focus trap, Escape and focus return.
 * A click on the backdrop (the dialog element itself) closes it too.
 */
export function useDialog() {
  const ref = useRef<HTMLDialogElement>(null);
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const dialog = ref.current;

Free component: copy it freely, including for commercial projects.

Modals components in React
  • A legal-age check window for a wine shop or brewery, accessible, remembered for the session and with the French Evin law notices.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short form in a window to request a call from an advisor.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A small window asking to confirm an action before running it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component