-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from openeuropa/OEL-3421
OEL-3421: Prerelease bcl.
- Loading branch information
Showing
8 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @file | ||
* Attaches behaviors for accessible Bootstrap components. | ||
*/ | ||
(function (bootstrap, Drupal) { | ||
|
||
/** | ||
* Attaches the accessible toggle behavior to Bootstrap components. | ||
* | ||
* @type {Drupal~behavior} | ||
* | ||
* @prop {Drupal~behaviorAttach} attach | ||
* Initializes AccessibleToggle for specified Bootstrap components. | ||
*/ | ||
Drupal.behaviors.accessibleToggle = { | ||
attach: function (context, settings) { | ||
bootstrap.AccessibleToggle.init([ | ||
{ selector: '[data-bs-toggle="modal"]', type: 'modal' }, | ||
{ selector: '[data-bs-toggle="offcanvas"]', type: 'offcanvas' } | ||
// Additional components like collapse can be added here in the future. | ||
]); | ||
} | ||
}; | ||
|
||
})(bootstrap, Drupal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\oe_bootstrap_theme\FunctionalJavascript; | ||
|
||
use Behat\Mink\Element\NodeElement; | ||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase; | ||
|
||
/** | ||
* Tests the AccessibleToggle behavior for modal and offcanvas. | ||
*/ | ||
class AccessibleToggleTest extends WebDriverTestBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $defaultTheme = 'oe_bootstrap_theme'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'oe_bootstrap_theme_helper', | ||
'system', | ||
'ui_patterns', | ||
'ui_patterns_library', | ||
'ui_patterns_settings', | ||
]; | ||
|
||
/** | ||
* Tests the ARIA attributes for modal and offcanvas triggers. | ||
*/ | ||
public function testAccessibleToggleAttributes(): void { | ||
$this->drupalLogin($this->drupalCreateUser([], NULL, TRUE)); | ||
$this->drupalGet('/admin/appearance/ui/patterns'); | ||
|
||
$modalTrigger = $this->getSession()->getPage()->find('css', '[data-bs-toggle="modal"]'); | ||
$offcanvasTrigger = $this->getSession()->getPage()->find('css', '[data-bs-toggle="offcanvas"]'); | ||
|
||
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE); | ||
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE); | ||
|
||
$modalTrigger->click(); | ||
$this->assertAccessibleAttributes($modalTrigger, expanded: TRUE); | ||
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE); | ||
|
||
$this->getSession()->getPage()->find('css', '.modal .btn-close')->click(); | ||
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE); | ||
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE); | ||
|
||
$offcanvasTrigger->click(); | ||
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE); | ||
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: TRUE); | ||
|
||
// Close offcanvas and check attribute updates. | ||
$this->getSession()->getPage()->find('css', '.offcanvas-backdrop')->click(); | ||
$this->assertAccessibleAttributes($modalTrigger, expanded: FALSE); | ||
$this->assertAccessibleAttributes($offcanvasTrigger, expanded: FALSE); | ||
} | ||
|
||
/** | ||
* Asserts the initial ARIA attributes for the triggers. | ||
* | ||
* @param \Behat\Mink\Element\NodeElement|null $trigger | ||
* The trigger element. | ||
* @param bool $expanded | ||
* The expected state of aria-expanded attribute. | ||
*/ | ||
protected function assertAccessibleAttributes(?NodeElement $trigger, bool $expanded): void { | ||
$this->assertNotNull($trigger); | ||
$this->assertEquals('true', $trigger->getAttribute('aria-haspopup')); | ||
$this->assertEquals($expanded ? 'true' : 'false', $trigger->getAttribute('aria-expanded')); | ||
} | ||
|
||
} |