Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
prototype
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
prototype
Merge requests
!150
Resolve
#3480037
"Nested menus with"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve
#3480037
"Nested menus with"
issue/prototype-3480037:3480037-nested-menus-with
into
5.x
Overview
36
Commits
9
Pipelines
2
Changes
7
Merged
Jennifer Dust
requested to merge
issue/prototype-3480037:3480037-nested-menus-with
into
5.x
6 months ago
Overview
36
Commits
9
Pipelines
2
Changes
7
Expand
Closes
#3480037
0
0
Merge request reports
Compare
5.x
version 7
ef3bf7b5
5 months ago
version 6
448b6cd6
5 months ago
version 5
b4ada2d3
5 months ago
version 4
96ad0ab8
5 months ago
version 3
d98d11d6
6 months ago
version 2
09ce25c7
6 months ago
version 1
d809aaf3
6 months ago
5.x (base)
and
latest version
latest version
ef3bf7b5
9 commits,
5 months ago
version 7
ef3bf7b5
9 commits,
5 months ago
version 6
448b6cd6
8 commits,
5 months ago
version 5
b4ada2d3
7 commits,
5 months ago
version 4
96ad0ab8
6 commits,
5 months ago
version 3
d98d11d6
5 commits,
6 months ago
version 2
09ce25c7
4 commits,
6 months ago
version 1
d809aaf3
3 commits,
6 months ago
7 files
+
305
−
133
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Some changes are not shown
For a faster browsing experience, some files are collapsed by default.
Expand all files
Files
7
Search (e.g. *.vue) (Ctrl+P)
components/02-components/menu/src/menu-aria-controls.js
+
42
−
14
Options
(
function
(
Drupal
)
{
(
function
(
Drupal
)
{
/**
* Attaches ARIA controls and data attributes to given elements.
*
* This function iterates over each element in the provided array and sets the appropriate
* ARIA attributes based on the element type (button or other).
*
* For buttons, it sets `aria-haspopup`, `aria-controls`, `data-menu-controls`, and `aria-label`.
* For other elements it sets `data-menu-controls`.
*
* `data-menu-controls` is an attribute used to support arrow keys in the MenuControl class.
*
* @param {HTMLElement[]} elements - An array of HTML elements to which ARIA controls will be attached.
*/
function
attachControls
(
elements
)
{
elements
.
forEach
(
function
(
element
)
{
const
id
=
element
.
getAttribute
(
'
data-plugin-id
'
);
const
submenu
=
element
.
nextElementSibling
;
if
(
element
.
tagName
.
toLowerCase
()
===
'
button
'
)
{
element
.
setAttribute
(
'
aria-haspopup
'
,
'
true
'
);
if
(
submenu
)
{
const
submenuId
=
`panel-
${
id
}
`
;
submenu
.
setAttribute
(
'
id
'
,
submenuId
);
element
.
setAttribute
(
'
aria-controls
'
,
submenuId
);
element
.
setAttribute
(
'
data-menu-controls
'
,
submenuId
);
element
.
setAttribute
(
'
aria-label
'
,
element
.
textContent
.
trim
());
}
}
else
if
(
submenu
)
{
const
submenuId
=
`panel-
${
id
}
`
;
submenu
.
setAttribute
(
'
id
'
,
submenuId
);
element
.
setAttribute
(
'
data-menu-controls
'
,
submenuId
);
}
});
}
/*------------------------------------*\
/*------------------------------------*\
- 01 - Drupal Aria Controls
- 01 - Drupal Aria
& Data
Controls
Attach aria controls to menu items
Attach aria
and data
controls to menu items
\*------------------------------------*/
\*------------------------------------*/
Drupal
.
behaviors
.
ariaControls
=
{
Drupal
.
behaviors
.
ariaControls
=
{
attach
:
function
(
context
)
{
attach
:
function
(
context
)
{
@@ -9,19 +44,12 @@
@@ -9,19 +44,12 @@
// Find top level menu buttons
// Find top level menu buttons
const
buttons
=
menu
.
querySelectorAll
(
'
:scope button.menu__link
'
);
const
buttons
=
menu
.
querySelectorAll
(
'
:scope button.menu__link
'
);
// Add aria controls for buttons & related submenus
// Find menu spans for megamenu items
buttons
.
forEach
(
function
(
button
)
{
const
spans
=
menu
.
querySelectorAll
(
'
:scope span.menu__link
'
);
const
id
=
button
.
getAttribute
(
'
data-plugin-id
'
);
button
.
setAttribute
(
'
aria-haspopup
'
,
'
true
'
);
const
submenu
=
button
.
nextElementSibling
;
// Attach controls to buttons and spans
if
(
submenu
)
{
attachControls
(
buttons
);
const
submenuId
=
`panel-
${
id
}
`
;
attachControls
(
spans
);
submenu
.
setAttribute
(
'
id
'
,
submenuId
);
button
.
setAttribute
(
'
aria-controls
'
,
submenuId
);
button
.
setAttribute
(
'
aria-label
'
,
button
.
textContent
.
trim
());
}
});
});
});
},
},
};
};
Loading