Skip to content

Commit 9714eaf

Browse files
committed
Fix aria-expanded for opened panels.
1 parent bbcc55c commit 9714eaf

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/View/Helper/BootstrapPanelHelper.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ protected function _cleanCurrent () {
185185
return $res;
186186
}
187187

188+
/**
189+
*
190+
* Return true if the current panel should be open (only for collapsible).
191+
*
192+
* @return true if the current panel should be open, false otherwize.
193+
*
194+
**/
195+
protected function _isOpen () {
196+
return (is_int($this->_groupPanelOpen)
197+
&& $this->_groupPanelOpen === $this->_groupPanelCount)
198+
|| $this->_groupPanelOpen === $this->_bodyId;
199+
}
200+
188201
protected function _createHeader ($title, $options = [], $titleOptions = []) {
189202
if (empty($titleOptions)) {
190203
$titleOptions = $options['title'] ;
@@ -198,13 +211,14 @@ protected function _createHeader ($title, $options = [], $titleOptions = []) {
198211
if ($this->_collapsible) {
199212
$options += [
200213
'role' => 'tab',
201-
'id' => $this->_headId
214+
'id' => $this->_headId,
215+
'open' => $this->_isOpen()
202216
];
203217
$this->_headId = $options['id'];
204218
$title = $this->Html->link($title, '#'.$this->_bodyId, [
205219
'data-toggle' => 'collapse',
206220
'data-parent' => $this->_groupId ? '#'.$this->_groupId : false,
207-
'aria-expanded' => true,
221+
'aria-expanded' => json_encode($options['open']),
208222
'aria-controls' => '#'.$this->_bodyId,
209223
'escape' => $options['escape']
210224
]);
@@ -231,9 +245,7 @@ protected function _createBody ($text = null, $options = []) {
231245
$options = $this->addClass($options, 'panel-body');
232246
$body = $this->Html->tag('div', $text, $options);
233247
if ($this->_collapsible) {
234-
$open = ((is_int($this->_groupPanelOpen)
235-
&& $this->_groupPanelOpen === $this->_groupPanelCount)
236-
|| $this->_groupPanelOpen === $this->_bodyId) ? ' in' : '';
248+
$open = $this->_isOpen() ? ' in' : '';
237249
$body = $this->Html->div('panel-collapse collapse'.$open, $text ? $body : null, [
238250
'role' => 'tabpanel',
239251
'aria-labelledby' => $this->_headId,

0 commit comments

Comments
 (0)