hooks/useSelectAllContent.ts

marimo · frontend/src/hooks/useSelectAllContent.ts · typescript · Apache-2.0
ui

Hook to enable Ctrl/Cmd-A select all in a referenced element.

// Source: https://github.com/marimo-team/marimo | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/* Copyright 2026 Marimo. All rights reserved. */

/**
 * Hook that enables Ctrl/Cmd-A to select all text content within a specific element
 * @param ref - React ref to the element whose content should be selectable
 * @param enabled - Whether the hook should be active (defaults to true)
 */
export function useSelectAllContent<T extends HTMLElement>(enabled = true) {
  const handleKeyDown = (event: React.KeyboardEvent<T>) => {
    if (!enabled) {
      return;
    }

    const element = event.currentTarget;

    // Check for Ctrl-A (Windows/Linux) or Cmd-A (Mac)
    const isSelectAll =

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key