Scenario

Nested list editing behavior is inconsistent

When editing nested lists (lists within list items), the behavior of Enter, Backspace, Delete, and Tab keys varies significantly across browsers. Creating, editing, and deleting nested list items can result in unexpected DOM structures or lost formatting.

formatting
Scenario ID
scenario-nested-list-behavior

Details

When editing nested lists (lists within list items), the behavior of Enter, Backspace, Delete, and Tab keys varies significantly across browsers. Creating, editing, and deleting nested list items can result in unexpected DOM structures or lost formatting.

Observed Behavior

Scenario 1: Pressing Enter in a nested list item

  • Chrome/Edge: Creates a new list item at the same nesting level
  • Firefox: May create a new list item or paragraph, behavior inconsistent
  • Safari: May create unexpected nesting levels

Scenario 2: Pressing Tab to indent a list item

  • Chrome/Edge: May create a nested list structure or use CSS indentation
  • Firefox: Behavior varies, may not support Tab indentation
  • Safari: May create nested lists or unexpected structures

Scenario 3: Pressing Backspace at the beginning of a nested list item

  • Chrome/Edge: May unindent the list item or delete it
  • Firefox: May delete the nested list or create malformed HTML
  • Safari: Behavior can be unpredictable

Scenario 4: Deleting a nested list

  • Chrome/Edge: May merge with parent list item or create empty list items
  • Firefox: May delete the entire nested structure unexpectedly
  • Safari: May create broken HTML structures

Impact

  • Difficult to implement consistent nested list editing
  • Users experience different behavior across browsers
  • Risk of creating malformed HTML
  • Loss of list structure when editing nested items

Browser Comparison

  • Chrome/Edge: Generally better support for nested lists, but behavior can still be inconsistent
  • Firefox: Less predictable nested list behavior
  • Safari: Most inconsistent, often creates unexpected structures

Workaround

Implement custom handling for nested list operations:

element.addEventListener('beforeinput', (e) => {
  if (e.inputType === 'insertParagraph') {
    const selection = window.getSelection();
    if (selection.rangeCount === 0) return;
    
    const range = selection.getRangeAt(0);
    const listItem = range.startContainer.closest('li');
    
    if (listItem) {
      // Check if we're in a nested list
      const parentList = listItem.closest('ul, ol');
      const parentListItem = parentList?.parentElement;
      
      if (parentListItem?.tagName === 'LI') {
        e.preventDefault();
        // Implement custom nested list item creation
        handleNestedListItemInsertion(listItem, range);
      }
    }
  }
  
  // Handle Tab for indentation
  if (e.inputType === 'insertText' && e.data === '\t') {
    const selection = window.getSelection();
    if (selection.rangeCount === 0) return;
    
    const range = selection.getRangeAt(0);
    const listItem = range.startContainer.closest('li');
    
    if (listItem) {
      e.preventDefault();
      // Implement custom indentation logic
      handleListIndentation(listItem);
    }
  }
});

References

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0099-nested-list-enter-chrome Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0134-nested-list-tab-indent Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0143-nested-list-backspace Windows 11 Desktop or Laptop Any Firefox 120.0 US draft

Browser compatibility

This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.

Confirmed
Draft
No case documented

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: indentation

Blockquote editing behavior varies across browsers

Editing text within blockquote elements in contenteditable behaves inconsistently across browsers. Pressing Enter, applying formatting, or pasting content may break the blockquote structure, create nested blockquotes, or behave unexpectedly.

4 cases
Tags: enter

Enter vs Shift+Enter behavior differs across browsers

The behavior of Enter and Shift+Enter keys in contenteditable elements varies across browsers. Enter may create a new paragraph, line break, or div, while Shift+Enter may create a line break or behave differently. The resulting DOM structure also varies.

1 case
Tags: list

List formatting is lost when editing list items

When editing text within list items, formatting such as bold, italic, or links may be lost or behave unexpectedly. The list structure itself may also be lost when certain operations are performed, such as pasting content or applying formatting.

3 cases
Tags: list

List item deletion behavior varies across browsers

When pressing Backspace or Delete at the beginning or end of a list item, the behavior varies significantly across browsers. Some browsers delete the list item and merge with adjacent content, while others may delete the entire list or create unexpected DOM structures.

3 cases
Tags: nested

Nested formatting elements create complex DOM structures

Applying multiple formatting operations (bold, italic, underline, etc.) creates nested HTML elements that can become complex and hard to manage. Browsers handle nested formatting differently, and the resulting DOM structure can be inconsistent.

3 cases

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.