Skip to main content

Sortable Container

<sl-sortable-container> | SlSortableContainer
Since 2.0 hub24

A container for sortable items.

Allow children of type sl-sortable-item to be sorted in the vertical orientation only.

Item 1 Item 2 Item 3
<sl-sortable-container>
  <sl-sortable-item>Item 1</sl-sortable-item>
  <sl-sortable-item>Item 2</sl-sortable-item>
  <sl-sortable-item>Item 3</sl-sortable-item>
</sl-sortable-container>

Change event

Emits an sl-change event when the order of the items changes.

Item 1 Item 2 Item 3

<sl-sortable-container id="order-change-example">
  <sl-sortable-item>Item 1</sl-sortable-item>
  <sl-sortable-item>Item 2</sl-sortable-item>
  <sl-sortable-item>Item 3</sl-sortable-item>
</sl-sortable-container>

<p id="order-change-result"></p>

<script>
  const container = document.getElementById('order-change-example');
  container.addEventListener('sl-change', (event) => {
    setTimeout(() => {
      document.getElementById('order-change-result').textContent =
        "New is order is: " +
        Array.from(container .querySelectorAll('sl-sortable-item'))
          .map(item => item.textContent)
          .join(', ');
    }, 100);
  });
</script>

Slots

Name Description
(default) The default slot.

Learn more about using slots.

Events

Name React Event Description Event Detail
sl-change When the sort order changes. -

Learn more about events.

Parts

Name Description
base The component’s base wrapper.

Learn more about customizing CSS parts.