From 750c7e1b9553e1a00b1e9fef04e83f9a2fd5af63 Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Mon, 3 Jan 2022 09:40:20 +0100 Subject: [PATCH] changed all data and aria attributes to short syntax (fixed #27) --- src/Accordion.php | 4 ++-- src/Breadcrumbs.php | 2 +- src/Carousel.php | 2 +- src/Dropdown.php | 12 ++++++------ src/LinkPager.php | 2 +- src/Modal.php | 10 +++++----- src/Nav.php | 6 +++--- src/Offcanvas.php | 18 ++++++++++-------- src/Toast.php | 2 +- tests/DropdownTest.php | 2 +- tests/OffcanvasTest.php | 2 +- tests/TabsTest.php | 6 +++--- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/Accordion.php b/src/Accordion.php index 519d4d8..6ec2e07 100644 --- a/src/Accordion.php +++ b/src/Accordion.php @@ -187,8 +187,8 @@ class Accordion extends Widget Html::addCssClass($options, ['visibility' => 'show']); } - if (!isset($options['aria-label'], $options['aria-labelledby'])) { - $options['aria-labelledby'] = $options['id'] . '-heading'; + if (!isset($options['aria']['label'], $options['aria']['labelledby'])) { + $options['aria']['labelledby'] = $options['id'] . '-heading'; } $encodeLabel = $item['encode'] ?? $this->encodeLabels; diff --git a/src/Breadcrumbs.php b/src/Breadcrumbs.php index f6de031..1607f3e 100644 --- a/src/Breadcrumbs.php +++ b/src/Breadcrumbs.php @@ -76,7 +76,7 @@ class Breadcrumbs extends Widget * @var array the HTML attributes for the widgets nav container tag. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. */ - public $navOptions = ['aria-label' => 'breadcrumb']; + public $navOptions = ['aria' => ['label' => 'breadcrumb']]; /** diff --git a/src/Carousel.php b/src/Carousel.php index 48ed861..0a1bf23 100644 --- a/src/Carousel.php +++ b/src/Carousel.php @@ -77,7 +77,7 @@ class Carousel extends Widget /** * {@inheritdoc} */ - public $options = ['data-bs-ride' => 'carousel']; + public $options = ['data' => ['bs-ride' => 'carousel']]; /** diff --git a/src/Dropdown.php b/src/Dropdown.php index 918c3eb..70ab63c 100644 --- a/src/Dropdown.php +++ b/src/Dropdown.php @@ -124,10 +124,10 @@ class Dropdown extends Widget Html::addCssClass($linkOptions, ['widget' => 'dropdown-item']); if ($disabled) { ArrayHelper::setValue($linkOptions, 'tabindex', '-1'); - ArrayHelper::setValue($linkOptions, 'aria-disabled', 'true'); + ArrayHelper::setValue($linkOptions, 'aria.disabled', 'true'); Html::addCssClass($linkOptions, ['disable' => 'disabled']); } elseif ($active) { - ArrayHelper::setValue($linkOptions, 'aria-current', 'true'); + ArrayHelper::setValue($linkOptions, 'aria.current', 'true'); Html::addCssClass($linkOptions, ['activate' => 'active']); } @@ -147,10 +147,10 @@ class Dropdown extends Widget Html::addCssClass($submenuOptions, ['widget' => 'dropdown-submenu dropdown-menu']); Html::addCssClass($linkOptions, ['toggle' => 'dropdown-toggle']); - $lines[] = Html::beginTag('div', array_merge_recursive(['class' => ['dropdown'], 'aria-expanded' => 'false'], $itemOptions)); - $lines[] = Html::a($label, $url, array_merge([ - 'data-bs-toggle' => 'dropdown', - 'aria-expanded' => 'false', + $lines[] = Html::beginTag('div', array_merge_recursive(['class' => ['dropdown'], 'aria' => ['expanded' => 'false']], $itemOptions)); + $lines[] = Html::a($label, $url, array_merge_recursive([ + 'data' => ['bs-toggle' => 'dropdown'], + 'aria' => ['expanded' => 'false'], 'role' => 'button', ], $linkOptions)); $lines[] = static::widget([ diff --git a/src/LinkPager.php b/src/LinkPager.php index f5e9ba5..ffaa8f7 100644 --- a/src/LinkPager.php +++ b/src/LinkPager.php @@ -288,7 +288,7 @@ class LinkPager extends Widget Html::addCssClass($options, $class ?: $this->pageCssClass); $linkOptions = $this->linkOptions; - $linkOptions['data-page'] = $page; + $linkOptions['data']['page'] = $page; if ($active) { $options['aria'] = ['current' => 'page']; diff --git a/src/Modal.php b/src/Modal.php index 342f0bc..c05a73c 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -282,8 +282,8 @@ class Modal extends Widget $this->titleOptions = array_merge([ 'id' => $this->options['id'] . '-label', ], $this->titleOptions); - if (!isset($this->options['aria-label'], $this->options['aria-labelledby']) && isset($this->title)) { - $this->options['aria-labelledby'] = $this->titleOptions['id']; + if (!isset($this->options['aria']['label'], $this->options['aria']['labelledby']) && isset($this->title)) { + $this->options['aria']['labelledby'] = $this->titleOptions['id']; } if ($this->closeButton !== false) { @@ -296,11 +296,11 @@ class Modal extends Widget if ($this->toggleButton !== false) { $this->toggleButton = array_merge([ - 'data-bs-toggle' => 'modal', + 'data' => ['bs-toggle' => 'modal'], 'type' => 'button', ], $this->toggleButton); - if (!isset($this->toggleButton['data-bs-target']) && !isset($this->toggleButton['href'])) { - $this->toggleButton['data-bs-target'] = '#' . $this->options['id']; + if (!isset($this->toggleButton['data']['bs-target']) && !isset($this->toggleButton['href'])) { + $this->toggleButton['data']['bs-target'] = '#' . $this->options['id']; } } diff --git a/src/Nav.php b/src/Nav.php index 4501e57..f44e55a 100644 --- a/src/Nav.php +++ b/src/Nav.php @@ -183,9 +183,9 @@ class Nav extends Widget Html::addCssClass($options, ['widget' => 'nav-item']); Html::addCssClass($linkOptions, ['widget' => 'nav-link']); } else { - $linkOptions['data-bs-toggle'] = 'dropdown'; + $linkOptions['data']['bs-toggle'] = 'dropdown'; $linkOptions['role'] = 'button'; - $linkOptions['aria-expanded'] = 'false'; + $linkOptions['aria']['expanded'] = 'false'; Html::addCssClass($options, ['widget' => 'dropdown nav-item']); Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle nav-link']); if (is_array($items)) { @@ -196,7 +196,7 @@ class Nav extends Widget if ($disabled) { ArrayHelper::setValue($linkOptions, 'tabindex', '-1'); - ArrayHelper::setValue($linkOptions, 'aria-disabled', 'true'); + ArrayHelper::setValue($linkOptions, 'aria.disabled', 'true'); Html::addCssClass($linkOptions, ['disable' => 'disabled']); } elseif ($this->activateItems && $active) { Html::addCssClass($linkOptions, ['activate' => 'active']); diff --git a/src/Offcanvas.php b/src/Offcanvas.php index fb5f7f6..cb855ad 100644 --- a/src/Offcanvas.php +++ b/src/Offcanvas.php @@ -223,16 +223,18 @@ class Offcanvas extends Widget { $this->options = array_merge([ 'tabindex' => -1, - 'data-bs-backdrop' => $this->backdrop ? 'true' : 'false', - 'data-bs-scroll' => $this->scrolling ? 'true' : 'false' + 'data' =>[ + 'bs-backdrop' => $this->backdrop ? 'true' : 'false', + 'bs-scroll' => $this->scrolling ? 'true' : 'false' + ] ], $this->options); Html::addCssClass($this->options, ['widget' => 'offcanvas offcanvas-' . $this->placement]); $this->titleOptions = array_merge([ 'id' => $this->options['id'] . '-label', ], $this->titleOptions); - if (!isset($this->options['aria-label'], $this->options['aria-labelledby']) && isset($this->title)) { - $this->options['aria-labelledby'] = $this->titleOptions['id']; + if (!isset($this->options['aria']['label'], $this->options['aria']['labelledby']) && isset($this->title)) { + $this->options['aria']['labelledby'] = $this->titleOptions['id']; } if ($this->closeButton !== false) { @@ -245,12 +247,12 @@ class Offcanvas extends Widget if ($this->toggleButton !== false) { $this->toggleButton = array_merge([ - 'data-bs-toggle' => 'offcanvas', + 'data' => ['bs-toggle' => 'offcanvas'], 'type' => 'button', - 'aria-controls' => $this->options['id'] + 'aria' => ['controls' => $this->options['id']] ], $this->toggleButton); - if (!isset($this->toggleButton['data-bs-target']) && !isset($this->toggleButton['href'])) { - $this->toggleButton['data-bs-target'] = '#' . $this->options['id']; + if (!isset($this->toggleButton['data']['bs-target']) && !isset($this->toggleButton['href'])) { + $this->toggleButton['data']['bs-target'] = '#' . $this->options['id']; } } } diff --git a/src/Toast.php b/src/Toast.php index 2ba5abd..eff3ba5 100644 --- a/src/Toast.php +++ b/src/Toast.php @@ -216,7 +216,7 @@ class Toast extends Widget if (!isset($this->options['role'])) { $this->options['role'] = 'alert'; } - if (!isset($this->options['aria']) && !isset($this->options['aria-live'])) { + if (!isset($this->options['aria']['live'])) { $this->options['aria'] = [ 'live' => 'assertive', 'atomic' => 'true', diff --git a/tests/DropdownTest.php b/tests/DropdownTest.php index cea4734..beab2dd 100644 --- a/tests/DropdownTest.php +++ b/tests/DropdownTest.php @@ -174,7 +174,7 @@ HTML; $expected = << diff --git a/tests/OffcanvasTest.php b/tests/OffcanvasTest.php index c32a4c6..dad015b 100644 --- a/tests/OffcanvasTest.php +++ b/tests/OffcanvasTest.php @@ -87,7 +87,7 @@ HTML; $out = ob_get_clean(); $this->assertContains( - '', + '', $out ); } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index fc6dd9b..2ca9528 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -180,7 +180,7 @@ class TabsTest extends TestCase ]); $this->assertContains( - '', + '', $html ); $this->assertContains( @@ -188,11 +188,11 @@ class TabsTest extends TestCase $html ); $this->assertContains( - '', + '', $html ); $this->assertContains( - 'DisabledItem', + 'DisabledItem', $html ); $this->assertContains(