---
title: "Desktop Manager"
description: "Desktop Manager component - desktop icons with the classic selection model: click, Ctrl and Shift, a rubber band drawn from an empty spot, keys, dragging icons to grid cells, F2 rename; opening, deleting and renaming are events."
slug: "desktop-manager"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, SourceNote, StatesSection, ApiSection, DocLink, SkillField, SkillText, SkillRow, ApiPill } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="desktop-manager" title="Desktop Manager" component="desktop-manager">
  The icons of a desktop, selected the way a desktop selects them. A click selects one icon, Ctrl or Cmd adds or removes one, Shift takes the range. Press on an empty spot and drag: a rubber band selects every icon it touches while it is drawn - with Ctrl the earlier selection stays - by mouse, pen or finger alike. Drag a selected icon and the whole selection moves, each icon landing on the grid cell under it. The keys work too: arrows go to the nearest icon on screen, Shift extends, Ctrl+A selects all, Enter opens, Delete deletes, F2 renames in place, Escape clears. Opening, deleting and renaming are events: the page decides what they mean. Inside a <DocLink href="window-manager.html">Window Manager</DocLink> the icons lie under the windows.
</PageHeader>

<SkillPanel component="desktop-manager">
  <SkillField label="Native basis">
<SkillText>A multi-select <code>role="listbox"</code> whose options are the icons (<code>aria-selected</code>, a roving <code>tabindex</code>), laid out on a CSS grid that fills columns top to bottom. Pointer Events drive the band and the drag for every pointer type.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events" title="mouse, pen and touch draw the same band"><code>Pointer Events</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/Element/setPointerCapture" title="a fast band never loses the pointer"><code>setPointerCapture()</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-auto-flow" title="icons fill a column, then the next"><code>grid-auto-flow: column</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable" title="F2 renames in place"><code>contenteditable</code></ApiPill>
    <ApiPill href="https://www.w3.org/WAI/ARIA/apg/patterns/listbox/" title="multi-select listbox keys"><code>listbox</code> pattern</ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors" title="the selection in Highlight"><code>forced-colors</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.desktop-manager</code> <code>.desktop-icon</code> <code>.desktop-icon-image</code> <code>.desktop-icon-label</code> <code>.desktop-manager-band</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Notes">
<SkillText dense>• <code>data-value</code> names an icon in every event (default: its label).</SkillText>
  <SkillText dense>• A press that moves less than 4px is a click; a click on one of several selected icons narrows the selection to it.</SkillText>
  <SkillText dense>• <code>data-on-wallpaper</code> sets white labels with a shadow for a picture behind the icons.</SkillText>
  </SkillField>
</SkillPanel>

```html example label="Select like a desktop" hint="Click, Ctrl / Cmd + click, Shift + click; press on the empty area and drag a rectangle; drag the selection somewhere else; try the arrows, Ctrl+A, Enter, Delete and F2. The line below lists every event."
<div class="grid gap-2">
  <label class="flex items-center gap-2 text-sm"
    >Look
    <select class="select" data-look style="width: auto">
      <option value="">Modern</option>
      <option value="win7">7</option>
      <option value="winxp">XP</option>
      <option value="win98">98</option>
      <option value="win95">95</option>
    </select></label
  >
  <div class="desktop" style="height: 19rem">
    <div
      class="desktop-manager"
      id="dm-demo"
      data-state-demo
      data-on-wallpaper
      role="listbox"
      aria-multiselectable="true"
      aria-label="Desktop"
      style="flex: 1; min-height: 0"
    >
      <div class="desktop-icon" role="option" data-value="computer">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="computer"></span></span>
        <span class="desktop-icon-label">Computer</span>
      </div>
      <div class="desktop-icon" role="option" data-value="documents">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="folder"></span></span>
        <span class="desktop-icon-label">Documents</span>
      </div>
      <div class="desktop-icon" role="option" data-value="pictures">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="picture"></span></span>
        <span class="desktop-icon-label">Pictures</span>
      </div>
      <div class="desktop-icon" role="option" data-value="notes">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="text"></span></span>
        <span class="desktop-icon-label">Meeting notes.txt</span>
      </div>
      <div class="desktop-icon" role="option" data-value="terminal">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="terminal"></span></span>
        <span class="desktop-icon-label">Terminal</span>
      </div>
      <div class="desktop-icon" role="option" data-value="trash">
        <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="trash"></span></span>
        <span class="desktop-icon-label">Recycle Bin</span>
      </div>
    </div>
  </div>
  <output class="text-sm text-muted-foreground" id="dm-log">Nothing selected</output>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const dm = document.querySelector('#dm-demo');
    const log = document.querySelector('#dm-log');
    dm.addEventListener(
      'desktop-select',
      (e) => (log.textContent = `Selected: ${e.detail.values.join(', ') || 'nothing'}`),
    );
    dm.addEventListener('desktop-open', (e) => (log.textContent = `Open: ${e.detail.values.join(', ')}`));
    dm.addEventListener('desktop-delete', (e) => (log.textContent = `Delete asked for: ${e.detail.values.join(', ')}`));
    dm.addEventListener(
      'desktop-rename',
      (e) => (log.textContent = `Renamed ${e.detail.value} to "${e.detail.label}"`),
    );
  });
</script>
<script>
  // the Look select: the .desktop next to it takes the period's look
  document.addEventListener('DOMContentLoaded', () => {
    const select = document.querySelector('[data-look]');
    const desk = select.closest('.grid').querySelector('.desktop');
    select.addEventListener('change', () => {
      if (select.value) desk.dataset.variant = select.value;
      else delete desk.dataset.variant;
    });
  });
</script>
```

```html example label="Sizes" hint="data-size sm and lg change the icons and their cells; the default sits between them."
<div class="grid gap-3">
  <div
    class="desktop-manager"
    data-size="sm"
    role="listbox"
    aria-multiselectable="true"
    aria-label="Small icons"
    style="min-height: 0; height: 6rem"
  >
    <div class="desktop-icon" role="option" data-value="a">
      <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="text"></span></span>
      <span class="desktop-icon-label">Small</span>
    </div>
  </div>
  <div
    class="desktop-manager"
    data-size="lg"
    role="listbox"
    aria-multiselectable="true"
    aria-label="Large icons"
    style="min-height: 0; height: 8rem"
  >
    <div class="desktop-icon" role="option" aria-selected="true" data-value="b">
      <span class="desktop-icon-image"><span class="desktop-glyph" data-glyph="text"></span></span>
      <span class="desktop-icon-label">Large, selected</span>
    </div>
  </div>
</div>
```

<StatesSection>
  <p class="text-sm text-muted-foreground m-0 mb-3">Named states via the shared State API, bound on each <code>.desktop-manager</code>:</p>
  <ul class="text-sm text-muted-foreground m-0 mb-3 ps-5">
    <li><code>default</code> - no icon selected</li>
    <li><code>selected</code> - <code>\{ values \}</code>: the icons named are selected, every other is not</li>
  </ul>
  <p class="text-sm text-muted-foreground m-0 mb-3">The selection is the truth: clicks, the band and the keys change it without <code>setState</code>, and <code>getState()</code> reads it back; every change sends <code>desktop-select</code>.</p>
  <p class="text-sm text-muted-foreground">The first example carries <code>data-state-demo</code>; <code>bun run screenshots</code> drives it via <code>el.api.setState(name)</code> and captures <code>screenshots/\{mode\}/desktop-manager-\{state\}.png</code>.</p>

Machine contract - verified against <a class="link" href="../schemas/desktop-manager.schema.json"><code>desktop-manager.schema.json</code></a> by <code>bun run verify</code>:

```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
```

</StatesSection>

<ApiSection component="desktop-manager" />

<SourceFiles component="desktop-manager" section="css" />

<SourceFiles component="desktop-manager" section="js">
  <SourceNote for="js">The selection model follows defuss-desktop's SelectionModel (MIT), rebuilt on Pointer Events.</SourceNote>
</SourceFiles>

</DocPage>
