Skip to content

Commit

Permalink
changed all data and aria attributes to short syntax (fixed #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
simialbi committed Jan 3, 2022
1 parent 3e9be2e commit 750c7e1
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public function renderItem(string $header, array $item, int $index): string
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;
Expand Down
2 changes: 1 addition & 1 deletion src/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']];


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Carousel extends Widget
/**
* {@inheritdoc}
*/
public $options = ['data-bs-ride' => 'carousel'];
public $options = ['data' => ['bs-ride' => 'carousel']];


/**
Expand Down
12 changes: 6 additions & 6 deletions src/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ protected function renderItems(array $items, array $options = []): string
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']);
}

Expand All @@ -147,10 +147,10 @@ protected function renderItems(array $items, array $options = []): string
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([
Expand Down
2 changes: 1 addition & 1 deletion src/LinkPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected function renderPageButton(string $label, int $page, string $class, boo
Html::addCssClass($options, $class ?: $this->pageCssClass);

$linkOptions = $this->linkOptions;
$linkOptions['data-page'] = $page;
$linkOptions['data']['page'] = $page;

if ($active) {
$options['aria'] = ['current' => 'page'];
Expand Down
10 changes: 5 additions & 5 deletions src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ protected function initOptions()
$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) {
Expand All @@ -296,11 +296,11 @@ protected function initOptions()

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'];
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public function renderItem($item): string
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)) {
Expand All @@ -196,7 +196,7 @@ public function renderItem($item): string

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']);
Expand Down
18 changes: 10 additions & 8 deletions src/Offcanvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,18 @@ protected function initOptions()
{
$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) {
Expand All @@ -245,12 +247,12 @@ protected function initOptions()

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'];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Toast.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected function initOptions()
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',
Expand Down
2 changes: 1 addition & 1 deletion tests/DropdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function testDisabled()

$expected = <<<HTML
<div id="w0" class="dropdown-menu"><div class="dropdown" aria-expanded="false">
<a class="dropdown-item disabled dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button" tabindex="-1" aria-disabled="true">Dropdown1</a>
<a class="dropdown-item disabled dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" aria-disabled="true" role="button" tabindex="-1">Dropdown1</a>
<div id="w1" class="submenu-list dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page1</h6>
<h6 class="dropdown-header">Page2</h6></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/OffcanvasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testTriggerButton()
$out = ob_get_clean();

$this->assertContains(
'<button type="button" class="btn btn-primary" data-bs-toggle="offcanvas" aria-controls="w0" data-bs-target="#w0">Launch demo offcanvas</button>',
'<button type="button" class="btn btn-primary" data-bs-toggle="offcanvas" data-bs-target="#w0" aria-controls="w0">Launch demo offcanvas</button>',
$out
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/TabsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ public function testDisabled()
]);

$this->assertContains(
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab0" data-bs-toggle="tab" role="tab" aria-controls="w0-tab0" tabindex="-1" aria-disabled="true">Page1</a></li>',
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab0" data-bs-toggle="tab" role="tab" aria-controls="w0-tab0" aria-disabled="true" tabindex="-1">Page1</a></li>',
$html
);
$this->assertContains(
'<li class="nav-item"><a class="nav-link active" href="#w0-tab1" data-bs-toggle="tab" role="tab" aria-controls="w0-tab1" aria-selected="true">Page2</a></li>',
$html
);
$this->assertContains(
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab2" data-bs-toggle="tab" role="tab" aria-controls="w0-tab2" tabindex="-1" aria-disabled="true">DisabledPage</a></li>',
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab2" data-bs-toggle="tab" role="tab" aria-controls="w0-tab2" aria-disabled="true" tabindex="-1">DisabledPage</a></li>',
$html
);
$this->assertContains(
'<a class="dropdown-item disabled" href="#w0-dd3-tab1" data-bs-toggle="tab" role="tab" aria-controls="w0-dd3-tab1" tabindex="-1" aria-disabled="true">DisabledItem</a>',
'<a class="dropdown-item disabled" href="#w0-dd3-tab1" data-bs-toggle="tab" role="tab" aria-controls="w0-dd3-tab1" aria-disabled="true" tabindex="-1">DisabledItem</a>',
$html
);
$this->assertContains(
Expand Down

0 comments on commit 750c7e1

Please sign in to comment.