Skip to content

Commit c74dafd

Browse files
makhmudjon-inadullaevMakhmudjon InadullaevMakhmudjon Inadullaev
authored
tab index implemented for each variant item (npm#244)
* tab index implemented for each variant item * we collapse on last element blur Co-authored-by: Makhmudjon Inadullaev <makhmudjon@Makhmudjons-MacBook-Pro-2.local> Co-authored-by: Makhmudjon Inadullaev <makhmudjon@MakhmudjonsMBP2.home>
1 parent 6052343 commit c74dafd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/theme/nav.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
variants:
288288
- title: Version 6.14.17 (Legacy Release)
289289
shortName: v6
290+
tabIndex: 1
290291
url: /cli/v6
291292
default: false
292293
children:
@@ -526,6 +527,7 @@
526527
description: Cleaning the slate
527528
- title: Version 7.24.2 (Legacy Release)
528529
shortName: v7
530+
tabIndex: 2
529531
url: /cli/v7
530532
default: false
531533
children:
@@ -781,6 +783,7 @@
781783
- title: Version 8.19.2 (Latest Release)
782784
shortName: v8
783785
url: /cli/v8
786+
tabIndex: 3
784787
default: true
785788
children:
786789
- title: CLI Commands

theme/src/components/variant-select.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ function VariantSelect(props) {
2929
return null;
3030
}
3131

32-
variantPages.forEach((match) => {
32+
/**
33+
* We should use '@primer/react' package, as '@primer/components' package depricated and moved to '@primer/react'.
34+
* We have no closing/opening control with current '@primer/components' package, so document.body click event used for closing purpose.
35+
*/
36+
// TODO: We should use 'setOpen' function returned by the useDetails hook when we move to '@primer/react' package. https://primer.style/react/deprecated/Dropdown
37+
function collapseDropdown () {
38+
document.body.click()
39+
}
40+
41+
variantPages.forEach((match, index) => {
3342
if (match.page.url === path) {
3443
selectedItem = match;
3544
}
3645

37-
items.push(<Dropdown.Item onClick={() => { window.location.href = match.page.url; }} key={match.variant.title}>{match.variant.title}</Dropdown.Item>);
46+
items.push(<Dropdown.Item onBlur={index === (variantPages.length - 1) ? collapseDropdown : undefined} tabIndex={match.variant.tabIndex} onClick={() => { window.location.href = match.page.url; }} key={match.variant.title}>{match.variant.title}</Dropdown.Item>);
3847
});
3948

4049
return (

0 commit comments

Comments
 (0)