Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ setAttribute(string $name, ?string $value): self
$markup->setAttribute('id', 'main-content');
$markup->setAttribute('data-user-id', '123');
$markup->setAttribute('role', 'navigation');
$markup->setAttribute('required', '');

// Remove an attribute (null value)
$markup->setAttribute('disabled', null);
Expand Down Expand Up @@ -1220,4 +1221,3 @@ $list = new Markup(
- [MarkupQueryBuilder](markup-query-builder.html) - Fluent query builder
- [MarkupCollection](markup-collection.html) - Collection methods
- [Getting Started](getting-started.html) - Introduction and first steps

9 changes: 6 additions & 3 deletions src/Markup.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public function classes( ?array $classes = null ) {
* Sets or removes an HTML attribute on the wrapper element.
*
* If value is provided, sets the attribute. If value is null, removes the attribute.
* For boolean attributes (e.g., disabled, readonly), pass the attribute name as the value.
* For boolean attributes (e.g., disabled, readonly), pass an empty string as the value.
*
* @since 1.0.0
*
Expand Down Expand Up @@ -1928,7 +1928,11 @@ private function wrapperOpenerTag(): string {
if ( ! empty( $this->wrapperAttributes ) ) {
$attributes = [];
foreach ( $this->wrapperAttributes as $attribute => $value ) {
$attributes[] = $attribute . '="' . $value . '"';
if ( '' === $value ) {
$attributes[] = $attribute;
} else {
$attributes[] = $attribute . '="' . htmlspecialchars( (string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8' ) . '"';
}
}
$attributesStr = ' ' . implode( ' ', $attributes );
} else {
Expand Down Expand Up @@ -2092,4 +2096,3 @@ private function renderSlot( MarkupSlot $slot ): string {
}

}