Implement fieldset element for Slipstream#224
Merged
jverkoey merged 5 commits intoNov 5, 2025
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sThis commit adds support for the HTML
fieldsetandlegendelements, which are used to group related form controls together.Key features:
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