Editable Text

Click-to-edit inline text with save on Enter/blur and cancel on Escape.

This component requires softui.js for interactive behavior.

Default

Click the text to edit it; clicking away saves.

With icon (shown on hover/focus)

Name:
John Doe
Email:
john.doe@example.com

Without icon (hover border is the hint)

Title:
Product Manager
City:
San Francisco
<!-- With icon (shown on hover/focus) -->
<div class="sui-editable">
  <span class="sui-editable-value">John Doe</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

<!-- Without icon (hover border is the hint) -->
<div class="sui-editable">
  <span class="sui-editable-value">Product Manager</span>
</div>

Underline

Company:
CloudMetrics Inc.
Website:
cloudmetrics.io
<div class="sui-editable sui-editable-underline">
  <span class="sui-editable-value">CloudMetrics Inc.</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

Sizes

Small editable text
Default editable text
Large editable text
<div class="sui-editable sui-editable-sm">
  <span class="sui-editable-value">Small editable text</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

<div class="sui-editable">
  <span class="sui-editable-value">Default editable text</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

<div class="sui-editable sui-editable-lg">
  <span class="sui-editable-value">Large editable text</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

With Events

Listen for sui-editable-save and sui-editable-cancel events.

Click me to edit
Events appear here
<div class="sui-editable" id="myEditable">
  <span class="sui-editable-value">Click me to edit</span>
  <svg class="sui-editable-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
    <path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
  </svg>
</div>

<script>
  document.getElementById('myEditable')
    .addEventListener('sui-editable-save', function(e) {
      console.log('Saved:', e.detail.value);
      console.log('Previous:', e.detail.previous);
    });

  document.getElementById('myEditable')
    .addEventListener('sui-editable-cancel', function() {
      console.log('Edit cancelled');
    });
</script>

Reference

Key / EventDescription
Enter, Space, F2Start editing (the text is a focusable button).
Enter / EscSave / cancel; focus returns to the text.
sui-editable-saveFires on save with detail.value and detail.previous; bubbles.
sui-editable-cancelFires on cancel; bubbles.
editable:save, editable:cancelOlder event names; still fire.

Delete this item?

This action cannot be undone. This will permanently delete the item and remove all associated data.