Popconfirm

Request a brief confirmation near the action element.

Live preview
Interact with the component to see results here.
View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      animation="none"
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>

Usage guide

#

Use for actions requiring a brief confirmation, such as deletion or reset. Use Modal for longer explanations or input.

  1. Place inside the action button

    Put the question in the default slot and make outcomes clear with confirmText and cancelText.

  2. Distinguish confirmation results

    Check for ok or cancel in selected.detail.

  3. Act only after confirmation

    Perform the actual action only after receiving ok. Do not run it on the button's initial click.

Examples

#

Confirm an action

Choose Archive or Cancel and inspect the result.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>

Display direction

Place the confirmation above the action element.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="top"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>

Allow dismissal

Provide a close button in addition to Confirm and Cancel.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      closable
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>

Direct control

Disable automatic triggers and control it through methods.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      trigger="none"
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>
<div class="demo-actions"
  style="display:flex;flex-wrap:wrap;gap:8px;margin-top:16px"
>
  <sy-button id="action-0" size="small">Open confirmation</sy-button>
  <sy-button id="action-1" size="small">Close</sy-button>
</div>
<output id="demo-result" aria-live="polite"></output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  const actionTarget0 = document.querySelector("#sample");
  document.querySelector('#action-0').addEventListener('click', async () => {
    const result = await actionTarget0.setOpen();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget1 = document.querySelector("#sample");
  document.querySelector('#action-1').addEventListener('click', async () => {
    const result = await actionTarget1.setClose();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
</script>

Events and payloads

Interact with the component and inspect the latest event name and detail. The code includes subscriptions to events emitted by this component and its children.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      arrow
      animation="none"
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>
<output id="demo-events" aria-live="polite">Interact with the component to see
  its latest event and payload.</output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  for (const name of ["visibleChanged", "selected"]) {
    document.addEventListener(name, event => {
      document.querySelector('#demo-events').textContent =
        `${event.target.localName} · ${name}: ${describeResult(event.detail)}`;
    });
  }
</script>

Confirmation without an arrow

Keep the confirmation actions while removing the pointer arrow.

View code
HTML
<div style="display:inline-flex;align-self:center;margin:70px 0">
  <sy-button>Archive item<sy-popconfirm
      position="bottom"
      confirmtext="Archive"
      canceltext="Cancel"
      animation="none"
      id="sample"
    ><span>Archive this example item?</span></sy-popconfirm>
  </sy-button>
</div>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "arrow": false
  });
</script>

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-popconfirm>

Properties

Attribute / PropertyTypeDefaultDescription
booleanfalseShow an arrow pointing to the trigger.
booleanfalseShow the close button.
'top' | 'bottom' | 'left' | 'right' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom''top'Popup placement relative to the trigger.
'click' | 'none''click'User action that opens the list or popup.
number0Opening delay in milliseconds.
number0Closing delay in milliseconds.
string'OK'Confirmation button text.
string'Cancel'Cancel button text.
booleanfalseStick to the top of the nearest scroll container.
| 'none' | 'fade' | 'fade-scale' | 'zoom' | 'pop' | 'slide-top' | 'slide-bottom' | 'slide-left' | 'slide-right' | 'slide-fade-top' | 'slide-fade-bottom' | 'slide-fade-left' | 'slide-fade-right' | 'reveal-top' | 'reveal-bottom' | 'reveal-left' | 'reveal-right' | 'flip-x' | 'flip-y' | 'bounce' | 'spin''none'Enter/exit animation type. `none` (default) toggles instantly.
'x-fast' | 'fast' | 'medium' | 'slow' | 'x-slow''fast'Animation playback speed token. Maps to `--transition-*` global tokens.

Events

EventDetailDescription
CustomEvent<boolean>Read the result from the event's detail.
CustomEvent<'ok' | 'cancel'>Emitted when the user selects an item.

Methods

MethodReturnsDescription
Promise<void>Expand the submenu.
Promise<void>Close the item.

Slots

SlotDescription
Component body or child items.