Slab
Slab

What's new

1.3.0

Date Time Picker, drag and drop beyond reordering with Draggable and Drop Zone, Sortable Lists that trade items, and smaller bundles.

1.3.0 brings drag and drop beyond reordering, and a picker for a date and a time. Date Time Picker opens a Calendar and a time input from a Date Time Field, so a day and then a time can be picked in one go. Draggable and Drop Zone drag something onto a place that takes it, such as a card from one column of a board to the next, with a mouse, a finger or the keyboard, and dispatch the drag events native drag and drop does however the drag is made. Sortable Lists with the same group trade items, each element now ships only its own English strings, and the docs' search finds every row of every API table. It's a minor release, so nothing needs changing.

TL;DR The short version

  1. Date Time Picker is Date Time Field with a button that opens a Calendar and a time input, and stays open after a day is picked so a time can follow.
  2. Draggable and Drop Zone drag something onto a place that takes it, by its handle with a mouse or a finger, or with Space, Enter and the arrow keys.
  3. However the drag is made, they dispatch "dragstart", "dragenter", "dragover", "dragleave", "drop" and "dragend" as DragEvents with a DataTransfer, so one "drop" listener covers them all.
  4. A Drop Zone takes what matches its accept, native drags from other windows too, and has :state(droppable) and :state(over) to show where things can go.
  5. Sortable Lists with the same group trade items, by dragging or with Left Arrow and Right Arrow, and both lists dispatch "change".
  6. Each element bundles only its own English strings rather than every element's, which takes up to about 1 KB, gzipped, off an app.
  7. The docs' search finds every attribute, property, method, event, slot, part and state, and the release notes.
  8. Nothing to change: it's additions and a fix to Table's types.

New components

Every one is live below, styled the way this site styles them.

  • In the job site's time zone. Trucks leave the plant an hour before.

    Date Time Picker

    Date Time Field, with a button that opens a Calendar and a native time input in a popover. Picking a day keeps the time and the picker open, so a time can follow, and months, week-start and isDateUnavailable work as on Date Picker.

    Docs for Date Time Picker
  • Footings Garage slab Foundation walls

    Draggable and Drop Zone

    A Draggable is dragged by its handle, with a mouse, a finger or the keyboard, onto a Drop Zone that takes what matches its accept. Both dispatch native drag events, and what a drop means is up to the page, which here moves the card to the column.

    Docs for Draggable and Drop Zone

Drag and drop, however it's done

Native drag and drop is a draggable attribute and a few events. It does nothing for the keyboard or screenreaders, its support on touch screens varies, and Firefox won't start a drag from a <button>. Draggable and Drop Zone keep the native events and make the rest work. A Draggable is dragged by its handle with a mouse or a finger, or picked up with Space or Enter and moved with the arrow keys, and every way of dragging dispatches the same DragEvents, with a DataTransfer you fill in "dragstart" and read in "drop". Neither element moves anything, as native drag and drop doesn't, so what a drop means stays yours.

1.2: native drag and drop, with no keyboard
<div draggable="true" id="footings">Footings</div>
<div id="done">Done</div>

<script type="module">
  const card = document.querySelector('#footings');
  const done = document.querySelector('#done');

  card.addEventListener('dragstart', (event) => {
    event.dataTransfer.setData('application/x-task', card.id);
  });

  done.addEventListener('dragover', (event) => event.preventDefault());

  done.addEventListener('drop', (event) => {
    const id = event.dataTransfer.getData('application/x-task');
    done.append(document.getElementById(id));
  });

  // …and a keyboard and screenreaders are yours to do.
</script>
1.3: the same events, from every way of dragging
<slab-draggable id="footings" label="Footings">Footings</slab-draggable>
<slab-drop-zone accept="application/x-task" label="Done"></slab-drop-zone>

<script type="module">
  const card = document.querySelector('#footings');
  const done = document.querySelector('slab-drop-zone');

  card.addEventListener('dragstart', (event) => {
    event.dataTransfer.setData('application/x-task', card.id);
  });

  done.addEventListener('drop', (event) => {
    const id = event.dataTransfer.getData('application/x-task');
    done.append(document.getElementById(id));
  });
</script>
  • Footings Walls Driveway

    Lists that trade items

    Sortable Lists with the same group move items between them by themselves, and still put them in order. With the keyboard, Left Arrow and Right Arrow change lists.

    index.html
    <div style="display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr))">
      <slab-sortable-list group="pours" label="This week" style="min-block-size: 8rem">
        <slab-sortable-list-item label="Footings">Footings</slab-sortable-list-item>
        <slab-sortable-list-item label="Walls">Walls</slab-sortable-list-item>
      </slab-sortable-list>
      <slab-sortable-list group="pours" label="Next week" style="min-block-size: 8rem">
        <slab-sortable-list-item label="Driveway">Driveway</slab-sortable-list-item>
      </slab-sortable-list>
    </div>
  • Only what fits

    A Drop Zone takes a drop only of what matches its accept, and of anything when it's unset. While something it takes is dragged, it's :state(droppable), so the places it can go stand out, and :state(over) while it's over it.

    index.html
    <slab-drop-zone accept="application/x-task, text/uri-list" label="Archive">
    </slab-drop-zone>
    
    <style>
      slab-drop-zone:state(droppable) {
        outline: 2px dashed;
      }
    
      slab-drop-zone:state(over) {
        background: lightyellow;
      }
    </style>
  • Was it dropped?

    Each Drop Zone's drop-effect, "move" to start, becomes the drag's dropEffect, so "dragend" says what happened, and "none" means it wasn't dropped at all, or was canceled with Escape.

    index.js
    card.addEventListener('dragend', (event) => {
      if (event.dataTransfer.dropEffect === 'none') {
        console.log('Footings stayed where it was.');
      }
    });

Read about Draggable and Drop Zone

Also new

  • Sortable List groups

    Give Sortable Lists the same group and an item dragged over another list moves there, landing where the pointer is. Left Arrow and Right Arrow move a picked up item to the previous or next list, and screenreaders hear "Walls moved to Done, position 1 of 2".

  • Native drags, from anywhere

    Drop Zones take native drags from outside Slab, such as a link or some text from another window, by the same accept, so the same "drop" listener handles them. Files are still for File Drop.

  • Smaller bundles

    Every element used to bundle every element's English strings. Now each has only its own, which takes up to about 1 KB, gzipped, off an app, however many elements it imports. registerStrings() and the Strings type are unchanged.

  • Search the API

    Ctrl+K, Command+K or "/" opens the search, which now finds each attribute, property, method, event, slot, part and state, such as showModal() or :state(open), beside its element, and each release.

Fixes

A line each, and the components it's in.

Types

  • Table Row's published types declare TableRowSelection again, so a project that type-checks with skipLibCheck: false no longer fails in table.row.class.d.ts.

Upgrade

Install
pnpm add slab-elements@1.3.0

Every change, in full, is in the release notes.