Skip to content

Implement fieldset element for Slipstream#224

Merged
jverkoey merged 5 commits into
mainfrom
claude/implement-fieldset-element-011CUpnU3nZVJiZBjsPBgErS
Nov 5, 2025
Merged

Implement fieldset element for Slipstream#224
jverkoey merged 5 commits into
mainfrom
claude/implement-fieldset-element-011CUpnU3nZVJiZBjsPBgErS

Conversation

@jverkoey

@jverkoey jverkoey commented Nov 5, 2025

Copy link
Copy Markdown
Collaborator

sThis commit adds support for the HTML fieldset and legend elements, which are used to group related form controls together.

Key features:

  • Fieldset element with support for disabled and name attributes
  • Legend element for providing captions for fieldsets
  • Comprehensive test coverage for both elements
  • Documentation updates reflecting the new implementations

The fieldset element follows Slipstream's established patterns, with a custom render() implementation similar to Form and Label. The legend element uses the W3CElement protocol like Caption and Abbreviation.

Part of #25

This commit adds support for the HTML <fieldset> and <legend> elements,
which are used to group related form controls together.

Key features:
- Fieldset element with support for disabled and name attributes
- Legend element for providing captions for fieldsets
- Comprehensive test coverage for both elements
- Documentation updates reflecting the new implementations

The fieldset element follows Slipstream's established patterns, with
a custom render() implementation similar to Form and Label. The legend
element uses the W3CElement protocol like Caption and Abbreviation.
This change makes Fieldset more consistent with SwiftUI patterns by using
a view modifier instead of an initializer parameter for the disabled state.

Changes:
- Added View+disabled.swift with a .disabled() modifier
- Removed disabled parameter from Fieldset initializer
- Updated Fieldset tests to use .disabled() modifier
- Updated documentation to reflect the new API

The .disabled() modifier can be applied to any view and sets the HTML
disabled attribute, which is particularly useful for form elements like
fieldset where it disables all descendant form controls.
The previous implementation had mismatched return types in the if/else
branches, causing a compilation error. This is fixed by introducing a
ConditionalAttributeModifier that properly handles boolean conditions
using @ViewBuilder.

Changes:
- Added ConditionalAttributeModifier to AttributeModifier.swift
- Updated .disabled() to use ConditionalAttributeModifier
- The modifier now properly handles both true and false conditions
  with matching return types

ConditionalAttributeModifier is designed for boolean HTML attributes
and can be reused for other similar attributes in the future.
SwiftSoup renders <legend> and <fieldset> elements without newlines
and indentation (inline format), similar to other form elements like
<label>. Updated test expectations to match this actual output.

Changes:
- Updated LegendTests to expect inline HTML format
- Updated FieldsetTests to expect inline HTML format
- Tests now match the actual SwiftSoup rendering behavior

Note: This differs from table elements (like <caption>) which do
render with formatting, but is consistent with other form elements.
SwiftSoup correctly recognizes <fieldset> as a block-level element and
renders it with newlines and indentation. Updated tests to match this
formatted output.

Also fixed attribute order in allAttributes test - attributes are
output in the order they're set (name first from render(), then
disabled from modifier).

Changes:
- Reverted to multi-line string expectations with proper formatting
- Fixed attribute order: "name" before "disabled"
- All tests now match actual SwiftSoup rendering behavior
@jverkoey jverkoey merged commit 699997f into main Nov 5, 2025
2 checks passed
@jverkoey jverkoey deleted the claude/implement-fieldset-element-011CUpnU3nZVJiZBjsPBgErS branch November 5, 2025 13:53
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.

2 participants