Skip to content

feat(icon-list): add nested sub-list support - #3181

Open
faisalahammad wants to merge 1 commit into
Codeinwp:masterfrom
faisalahammad:feature/3132-nested-icon-list-items
Open

faisalahammad wants to merge 1 commit into
Codeinwp:masterfrom
faisalahammad:feature/3132-nested-icon-list-items

Conversation

@faisalahammad

Copy link
Copy Markdown

Closes #3132.

Summary

The Icon List block can now hold nested lists. Any item can contain a full Icon List as a sub-list, added from the item toolbar or the "Add Sub-list" button under the item text. New sub-lists start with the parent list defaults (icons, colors, sizes), and every level keeps its own settings.

  • New "Sub-list Indent" control in Inspector > Style > Dimensions (default 32px). Nested lists inherit the value live from the parent list, and a sub-list can set its own value for deeper levels.
  • Lists get role="list" and items role="listitem" so screen readers announce the nesting. Items without a sub-list serialize exactly as before, and pre-nesting content loads through deprecations without invalid block warnings.
  • Divider and vertical layout rules are scoped to direct children per list level, with editor DOM mirrors, so a parent's divider settings do not leak into sub-lists.
  • Backspace at the start of an item with a sub-list moves the sub-list to the previous item before merging, so it is not deleted.
  • The shared BlockAppender component accepts seed attributes for the block it inserts. Backwards compatible, tabs and accordion e2e still pass.

Test instructions

  1. Build the branch (npm ci && composer install && npm run build) or install the built zip, and open a post in the editor.
  2. Insert an Icon List, click into an item, and use "Add Sub-list" (toolbar or under the item text). A nested Icon List appears with the parent's icon defaults. Repeat inside a nested item for a third level.
  3. Set a distinctive default icon and colors on the parent, add a sub-list, and confirm it inherits them. Change the sub-list's own settings and confirm the parent is unaffected.
  4. On the parent list, change "Sub-list Indent" and confirm existing nested lists move in the editor and on the frontend after saving. Set a different value on a sub-list and confirm it applies to deeper levels.
  5. Save and view the frontend: nested lists render inside the item (which gains has-sublist), lists carry role="list", items role="listitem".
  6. Open a post saved with an older Otter version containing flat Icon Lists (including dividers, horizontal style, image icons): no invalid content warnings, appearance unchanged apart from the roles.
  7. With a divider enabled on a vertical list, add a sub-list to a middle item. Toggle dividers per level and confirm settings stay scoped to each list. Repeat horizontally.
  8. Press Enter mid-text to split an item. Press Backspace at the start of an item with a sub-list: text merges into the previous item and the sub-list survives.

Automated coverage: jest (sub-list attribute seeding), PHPUnit (tests/test-icon-list-css.php, indent CSS including the numeric-string guard), Playwright (src/blocks/test/e2e/blocks/icon-list.spec.js: nesting, inheritance, live indent, serialization roles, old-content validity). Full suites green: jest 372/372, PHPUnit 821 (11 pre-existing skips), phpcs, PHPStan level 6, eslint 0 errors, icon-list e2e 6/6, tabs/accordion e2e 10/10.


Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

Items can now hold a nested Icon List. The sub-list is added from the
item toolbar or the button under the item text, and it starts with the
parent list defaults for icons, colors and sizes.

- New Sub-list Indent control in Dimensions. Nested lists inherit the
  value live from the parent, and a sub-list can override it for deeper
  levels.
- Lists and items get list/listitem roles. Items without a sub-list
  keep the exact previous markup, and old content loads through
  deprecations without warnings.
- Divider and vertical layout rules are scoped per list level, in the
  editor and on the frontend.
- Backspace merge moves the sub-list to the previous item instead of
  dropping it.
- BlockAppender accepts seed attributes for the inserted block.

Fixes Codeinwp#3132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support nested items and sub-lists in Icon List block

1 participant