-
Notifications
You must be signed in to change notification settings - Fork 2
Port FormGroup to Bootstrap 5 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed73412
b77c410
f549731
1bbcad5
4d4678a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,25 +19,65 @@ | |
| use Ease\Html\DivTag; | ||
| use Ease\Html\H5Tag; | ||
|
|
||
| /** | ||
| * Bootstrap Offcanvas slide-in panel. | ||
| * | ||
| * @see https://getbootstrap.com/docs/5.3/components/offcanvas/ | ||
| * | ||
| * @author Vítězslav Dvořák <info@vitexsoftware.cz> | ||
| */ | ||
| class OffCanvas extends DivTag | ||
| { | ||
| public function __construct($id, $title, $bodyContent) | ||
| { | ||
| $header = new DivTag( | ||
| [ | ||
| new H5Tag($title, ['class' => 'offcanvas-title', 'id' => $id.'Label']), | ||
| new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => 'Close']), | ||
| ], | ||
| ['class' => 'offcanvas-header'], | ||
| ); | ||
|
|
||
| $body = new DivTag($bodyContent, ['class' => 'offcanvas-body']); | ||
|
|
||
| parent::__construct([$header, $body], [ | ||
| 'class' => 'offcanvas offcanvas-start show', | ||
| public DivTag $header; | ||
| public DivTag $body; | ||
|
|
||
| /** | ||
| * Bootstrap Offcanvas. | ||
| * | ||
| * @param string $id Unique offcanvas ID | ||
| * @param mixed $title Header title | ||
| * @param mixed $bodyContent Offcanvas body content | ||
| * @param string $placement start|end|top|bottom | ||
| * @param array<string, string> $properties Additional offcanvas div properties | ||
| */ | ||
| public function __construct( | ||
| string $id, | ||
| $title = null, | ||
| $bodyContent = null, | ||
| string $placement = 'start', | ||
| array $properties = [] | ||
| ) { | ||
| parent::__construct(null, array_merge([ | ||
| 'tabindex' => '-1', | ||
| 'id' => $id, | ||
| 'aria-labelledby' => $id.'Label', | ||
| ], $properties)); | ||
| $this->addTagClass('offcanvas offcanvas-'.$placement); | ||
| $this->setTagID($id); | ||
|
|
||
| $this->header = new DivTag([ | ||
| new H5Tag($title, ['class' => 'offcanvas-title', 'id' => $id.'Label']), | ||
| new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => 'Close']), | ||
| ], ['class' => 'offcanvas-header']); | ||
|
Comment on lines
+57
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize the close button label.
Suggested fix- new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => 'Close']),
+ new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => _('Close')]),🤖 Prompt for AI Agents |
||
|
|
||
| $this->body = new DivTag($bodyContent, ['class' => 'offcanvas-body']); | ||
|
|
||
| $this->addItem($this->header); | ||
| $this->addItem($this->body); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a button that toggles this offcanvas. | ||
| * | ||
| * @param mixed $label Button label | ||
| * @param string $type primary|secondary|success|danger|warning|info|light|dark | ||
| */ | ||
| public function triggerButton($label, string $type = 'primary'): ButtonTag | ||
| { | ||
| return new ButtonTag($label, [ | ||
| 'class' => 'btn btn-'.$type, | ||
| 'data-bs-toggle' => 'offcanvas', | ||
| 'data-bs-target' => '#'.$this->getTagID(), | ||
| 'aria-controls' => $this->getTagID(), | ||
| ]); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve an accessible name when
$titleis omitted.$titleis nullable, but this constructor always setsaria-labelledbyand always renders the heading node. When callers passnull, the offcanvas ends up labelled by an empty element, which leaves it unnamed for assistive tech and can override a caller-suppliedaria-label.Suggested fix
public function __construct( string $id, $title = null, $bodyContent = null, string $placement = 'start', array $properties = [] ) { - parent::__construct(null, array_merge([ - 'tabindex' => '-1', - 'aria-labelledby' => $id.'Label', - ], $properties)); + $defaultProperties = ['tabindex' => '-1']; + + if ($title !== null) { + $defaultProperties['aria-labelledby'] = $id.'Label'; + } elseif (!isset($properties['aria-label'], $properties['aria-labelledby'])) { + $defaultProperties['aria-label'] = 'Offcanvas'; + } + + parent::__construct(null, array_merge($defaultProperties, $properties)); $this->addTagClass('offcanvas offcanvas-'.$placement); $this->setTagID($id); - $this->header = new DivTag([ - new H5Tag($title, ['class' => 'offcanvas-title', 'id' => $id.'Label']), - new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => 'Close']), - ], ['class' => 'offcanvas-header']); + $headerItems = []; + + if ($title !== null) { + $headerItems[] = new H5Tag($title, ['class' => 'offcanvas-title', 'id' => $id.'Label']); + } + + $headerItems[] = new ButtonTag('', ['class' => 'btn-close', 'data-bs-dismiss' => 'offcanvas', 'aria-label' => 'Close']); + + $this->header = new DivTag($headerItems, ['class' => 'offcanvas-header']);🤖 Prompt for AI Agents