Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.1.1 under development

- Enh #306: Raise `yiisoft/html` version to `^3.13 || ^4.0` (@vjik)
- Enh #305: Add `tabIndex()` method to `Button` widget (@Mister-42)

## 1.1.0 March 06, 2026
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require": {
"php": "8.1 - 8.5",
"yiisoft/html": "^3.0",
"yiisoft/html": "^3.13 || ^4.0",
"yiisoft/widget": "^2.0"
},
"require-dev": {
Expand Down
8 changes: 4 additions & 4 deletions src/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public function render(): string

$id = $this->getId();

return Div::tag()
return (new Div())
->addAttributes($attributes)
->addClass(self::NAME, $classes, ...$this->cssClasses)
->addContent("\n", $this->renderItems($id), "\n")
Expand Down Expand Up @@ -569,14 +569,14 @@ private function renderBody(AccordionItem $accordionItem, string $parentId, stri

unset($bodyAttributes['class'], $collapseAttributes['class']);

return Div::tag()
return (new Div())
->attribute('data-bs-parent', $this->alwaysOpen ? null : '#' . $parentId)
->addAttributes($collapseAttributes)
->addClass(self::CLASS_COLLAPSE, $accordionItem->isActive() ? 'show' : null, $classesCollapseAttributes)
->id($collapseId)
->addContent(
"\n",
Div::tag()
(new Div())
->addAttributes($bodyAttributes)
->addClass(self::CLASS_BODY, $classesBodyAttributes)
->addContent("\n", $accordionItem->getBody(), "\n")
Expand Down Expand Up @@ -658,7 +658,7 @@ private function renderItem(AccordionItem $accordionItem, string $parentId): str
/** @psalm-var non-empty-string $collapseId */
$collapseId = $accordionItem->getId();

return Div::tag()->addClass(self::CLASS_ITEM)
return (new Div())->addClass(self::CLASS_ITEM)
->addContent(
"\n",
$this->renderHeader($accordionItem, $collapseId),
Expand Down
2 changes: 1 addition & 1 deletion src/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function render(): string

$content = preg_replace("/\n{2}/", "\n", $content) ?? '';

return Div::tag()->addAttributes($attributes)->content($content)->encode(false)->id($this->getId())->render();
return (new Div())->addAttributes($attributes)->content($content)->encode(false)->id($this->getId())->render();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function render(): string
}


return Nav::tag()
return (new Nav())
->addAttributes($attributes)
->addClass(...$this->cssClasses)
->content("\n", $this->renderList(), "\n")
Expand Down Expand Up @@ -493,7 +493,7 @@ private function renderItem(BreadcrumbLink $breadcrumbLink): string
$itemsAttributes['aria-current'] = 'page';
}

return Li::tag()
return (new Li())
->addAttributes($itemsAttributes)
->addClass(
self::ITEM_NAME,
Expand All @@ -519,7 +519,7 @@ private function renderLink(BreadcrumbLink $breadcrumbLink): string

return match ($url) {
null => $label,
default => A::tag()
default => (new A())
->attributes($this->linkAttributes)
->addAttributes($breadcrumbLink->getAttributes())
->content($label)
Expand Down
4 changes: 2 additions & 2 deletions src/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public function type(ButtonType $type): self
{
$new = clone $this;
$new->tag = match ($type) {
ButtonType::LINK => A::tag(),
ButtonType::LINK => (new A()),
ButtonType::RESET => ButtonTag::reset(''),
ButtonType::RESET_INPUT => Input::resetButton(),
ButtonType::SUBMIT => ButtonTag::submit(''),
Expand Down Expand Up @@ -584,7 +584,7 @@ public function render(): string
{
$attributes = $this->attributes;
$classes = $attributes['class'] ?? null;
$tag = $this->tag ?? ButtonTag::tag()->button('');
$tag = $this->tag ?? (new ButtonTag())->button('');

unset($attributes['class'], $attributes['id']);

Expand Down
2 changes: 1 addition & 1 deletion src/ButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function render(): string
return '';
}

return Div::tag()
return (new Div())
->attributes($attributes)
->attribute('role', 'group')
->addClass(
Expand Down
2 changes: 1 addition & 1 deletion src/ButtonToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function render(): string
return '';
}

return Div::tag()
return (new Div())
->attributes($attributes)
->attribute('role', 'toolbar')
->addClass(
Expand Down
30 changes: 15 additions & 15 deletions src/Carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
* <?= Carousel::widget()
* ->id('carouselExample')
* ->items(
* CarouselItem::to(Img::tag()->alt('First slide')->src('image-1.jpg'), active: true),
* CarouselItem::to(Img::tag()->alt('Second slide')->src('image-2.jpg')),
* CarouselItem::to(Img::tag()->alt('Third slide')->src('image-3.jpg')),
* CarouselItem::to((new Img())->alt('First slide')->src('image-1.jpg'), active: true),
* CarouselItem::to((new Img())->alt('Second slide')->src('image-2.jpg')),
* CarouselItem::to((new Img())->alt('Third slide')->src('image-3.jpg')),
* )
* ?>
* ```
Expand Down Expand Up @@ -409,9 +409,9 @@ public function id(bool|string $id): self
* Example usage:
* ```php
* $carousel->items(
* CarouselItem::to(Img::tag()->alt('First slide')->src('image-1.jpg'), active: true),
* CarouselItem::to(Img::tag()->alt('Second slide')->src('image-2.jpg')),
* CarouselItem::to(Img::tag()->alt('Third slide')->src('image-3.jpg')),
* CarouselItem::to((new Img())->alt('First slide')->src('image-1.jpg'), active: true),
* CarouselItem::to((new Img())->alt('Second slide')->src('image-2.jpg')),
* CarouselItem::to((new Img())->alt('Third slide')->src('image-3.jpg')),
* );
*/
public function items(CarouselItem ...$items): self
Expand Down Expand Up @@ -498,7 +498,7 @@ public function render(): string

Html::addCssClass($attributes, [self::NAME, self::CLASS_SLIDE, $classes, ...$this->cssClasses]);

return Div::tag()
return (new Div())
->attributes($attributes)
->addContent(
"\n",
Expand Down Expand Up @@ -549,12 +549,12 @@ private function renderControlNext(string $id): string
->addClass(self::CLASS_CAROUSEL_CONTROL_NEXT)
->addContent(
"\n",
Span::tag()
(new Span())
->addAttributes(['aria-hidden' => 'true'])
->addClass(self::CLASS_CAROUSEL_CONTROL_NEXT_ICON)
->render(),
"\n",
Span::tag()->addClass('visually-hidden')->addContent($this->controlNextLabel)->render(),
(new Span())->addClass('visually-hidden')->addContent($this->controlNextLabel)->render(),
"\n",
)
->encode(false)
Expand All @@ -580,12 +580,12 @@ private function renderControlPrevious(string $id): string
->addClass(self::CLASS_CAROUSEL_CONTROL_PREV)
->addContent(
"\n",
Span::tag()
(new Span())
->addAttributes(['aria-hidden' => 'true'])
->addClass(self::CLASS_CAROUSEL_CONTROL_PREV_ICON)
->render(),
"\n",
Span::tag()->addClass('visually-hidden')->addContent($this->controlPreviousLabel)->render(),
(new Span())->addClass('visually-hidden')->addContent($this->controlPreviousLabel)->render(),
"\n",
)
->encode(false)
Expand Down Expand Up @@ -643,7 +643,7 @@ private function renderItem(CarouselItem $carouselItem, bool $active): string
);
}

$captionContainerTag = Div::tag()
$captionContainerTag = (new Div())
->addClass(self::CLASS_CAROUSEL_CAPTION)
->addContent(
"\n",
Expand All @@ -658,7 +658,7 @@ private function renderItem(CarouselItem $carouselItem, bool $active): string
) . "\n";
}

return Div::tag()
return (new Div())
->addClass(
self::CLASS_CAROUSEL_ITEM,
$carouselItem->isActive() || $active ? 'active' : null,
Expand Down Expand Up @@ -704,15 +704,15 @@ private function renderItems(string $id): string
}

if ($this->showIndicators) {
$renderIndicators = Div::tag()
$renderIndicators = (new Div())
->addClass(self::CLASS_CAROUSEL_INDICATORS)
->addContent("\n" . implode("\n", $indicators) . "\n")
->encode(false)
->render() . "\n";
}

return $renderIndicators
. Div::tag()
. (new Div())
->addClass(self::CLASS_CAROUSEL_INNER)
->addContent("\n" . implode("\n", $items) . "\n")
->encode(false)
Expand Down
8 changes: 4 additions & 4 deletions src/Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ public function render(): string

foreach ($this->items as $item) {
if ($item->getContent() !== '') {
$collapseDiv = Div::tag()
$collapseDiv = (new Div())
->addClass(self::NAME, ...$this->cssClasses)
->addAttributes($this->attributes)
->addContent(
"\n",
Div::tag()
(new Div())
->addAttributes($this->cardBodyAttributes)
->addClass(self::CARD, self::CARD_BODY)
->addContent(
Expand All @@ -378,7 +378,7 @@ public function render(): string
$collapseDiv = $collapseDiv->addClass(self::COLLAPSE_MULTIPLE);

if ($item->getTogglerMultiple() === false) {
$collapse[] = Div::tag()->addClass('col')->addContent("\n", $collapseDiv, "\n");
$collapse[] = (new Div())->addClass('col')->addContent("\n", $collapseDiv, "\n");
}
} else {
$collapse[] = $collapseDiv;
Expand All @@ -403,7 +403,7 @@ private function renderCollapse(array $collapse): string
$collapseContent = implode("\n", $collapse);

return $this->container
? Div::tag()
? (new Div())
->addAttributes($this->containerAttributes)
->addContent("\n", $collapseContent, "\n")
->encode(false)
Expand Down
30 changes: 15 additions & 15 deletions src/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function theme(string $theme): self
* Example usage:
* ```php
* $dropdown->toggler(
* Button::tag()
* (new Button())
* ->addAttributes(
* [
* 'data-bs-toggle' => 'dropdown',
Expand Down Expand Up @@ -773,7 +773,7 @@ public function render(): string
$renderItems = $this->renderItems($togglerId);

return match ($this->container) {
true => Div::tag()
true => (new Div())
->addAttributes($attributes)
->addClass(...$containerClasses)
->addClass($classes)
Expand Down Expand Up @@ -835,7 +835,7 @@ private function renderItem(DropdownItem $item): Li
*/
private function renderItemButton(DropdownItem $item): Li
{
return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent(
"\n",
Expand All @@ -856,11 +856,11 @@ private function renderItemButton(DropdownItem $item): Li
*/
private function renderItemDivider(DropdownItem $item): Li
{
return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent(
"\n",
Hr::tag()->addAttributes($item->getItemAttributes())->addClass(self::DROPDOWN_ITEM_DIVIDER_CLASS),
(new Hr())->addAttributes($item->getItemAttributes())->addClass(self::DROPDOWN_ITEM_DIVIDER_CLASS),
"\n",
);
}
Expand All @@ -874,7 +874,7 @@ private function renderItemDivider(DropdownItem $item): Li
*/
private function renderItemHeader(DropdownItem $item): Li
{
return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent(
"\n",
Expand Down Expand Up @@ -908,11 +908,11 @@ private function renderItemLink(DropdownItem $item): Li
$itemAttributes['aria-disabled'] = 'true';
}

return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent(
"\n",
A::tag()->addAttributes($itemAttributes)->content($item->getContent())->url($item->getUrl()),
(new A())->addAttributes($itemAttributes)->content($item->getContent())->url($item->getUrl()),
"\n",
);
}
Expand All @@ -926,7 +926,7 @@ private function renderItemLink(DropdownItem $item): Li
*/
private function renderListContentItem(DropdownItem $item): Li
{
return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent("\n", $item->getContent(), "\n")
->encode(false);
Expand All @@ -941,11 +941,11 @@ private function renderListContentItem(DropdownItem $item): Li
*/
private function renderItemText(DropdownItem $item): Li
{
return Li::tag()
return (new Li())
->addAttributes($item->getAttributes())
->addContent(
"\n",
Span::tag()
(new Span())
->addAttributes($item->getItemAttributes())
->addClass(self::DROPDOWN_ITEM_TEXT_CLASS)
->content($item->getContent())
Expand Down Expand Up @@ -973,7 +973,7 @@ private function renderItems(?string $togglerId): string
}
}

$ulTag = Ul::tag()
$ulTag = (new Ul())
->addAttributes(['aria-labelledby' => $togglerId])
->addClass(self::DROPDOWN_LIST_CLASS, ...$this->alignmentClasses)
->items(...$items);
Expand All @@ -998,7 +998,7 @@ private function renderToggler(?string $togglerId): string

$togglerContent = match ($this->togglerSplit) {
true => "\n"
. Span::tag()
. (new Span())
->addContent($this->togglerContent)
->addClass(self::DROPDOWN_TOGGLER_SPAN_CLASS)
->render()
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private function renderToggler(?string $togglerId): string
*/
private function renderTogglerLink(array $togglerAttributes, string $togglerContent): string
{
return A::tag()
return (new A())
->addAttributes($togglerAttributes)
->attribute('role', 'button')
->attribute('data-bs-toggle', 'dropdown')
Expand All @@ -1070,7 +1070,7 @@ private function renderTogglerLink(array $togglerAttributes, string $togglerCont
private function renderTogglerSplit(): string
{
if ($this->togglerLink) {
return A::tag()
return (new A())
->addAttributes(['role' => 'button'])
->addClass(
self::DROPDOWN_TOGGLER_BUTTON_CLASS,
Expand Down
Loading
Loading