Skip to content

Commit 1aa14a0

Browse files
committed
fix dropdown behavior for repo permissions, make elements inside menu item non-focusable
1 parent 3fc33c3 commit 1aa14a0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

templates/repo/settings/collaboration.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</div>
2020
<div class="ui eight wide column">
2121
{{svg "octicon-shield-lock"}}
22-
<div class="ui inline dropdown access-mode" data-url="{{$.Link}}/access_mode" data-uid="{{.ID}}">
22+
<div class="ui inline dropdown access-mode" data-url="{{$.Link}}/access_mode" data-uid="{{.ID}}" data-last-value="{{printf "%d" .Collaboration.Mode}}">
2323
<div class="text">{{if eq .Collaboration.Mode 1}}{{$.i18n.Tr "repo.settings.collaboration.read"}}{{else if eq .Collaboration.Mode 2}}{{$.i18n.Tr "repo.settings.collaboration.write"}}{{else if eq .Collaboration.Mode 3}}{{$.i18n.Tr "repo.settings.collaboration.admin"}}{{else}}{{$.i18n.Tr "repo.settings.collaboration.undefined"}}{{end}}</div>
2424
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2525
<div class="menu">

web_src/js/features/aria.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ function generateAriaId() {
88

99
// make the item has role=option, and add an id if there wasn't one yet.
1010
function prepareMenuItem($item) {
11-
$item.attr({'role': 'option'});
1211
if (!$item.attr('id')) $item.attr('id', generateAriaId());
12+
$item.attr({'role': 'option', 'tabindex': '-1'});
13+
$item.find('a').attr('tabindex', '-1'); // as above, the elements inside the dropdown menu item should not be focusable, the focus should always be on the dropdown primary element.
1314
}
1415

1516
// when the menu items are loaded from AJAX requests, the items are created dynamically

web_src/js/features/repo-settings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ const {appSubUrl, csrfToken} = window.config;
77
export function initRepoSettingsCollaboration() {
88
// Change collaborator access mode
99
const $dropdown = $('.page-content.repository .ui.dropdown.access-mode');
10+
const $text = $dropdown.find('> .text');
1011
$dropdown.dropdown({
1112
action (_text, value) {
1213
$.post($dropdown.attr('data-url'), {
1314
_csrf: csrfToken,
1415
uid: $dropdown.attr('data-uid'),
1516
mode: value,
1617
});
18+
$dropdown.attr('data-last-value', value);
1719
$dropdown.dropdown('hide');
20+
},
21+
onChange (_value, text, _$choice) {
22+
$text.text(text); // update the text when using keyboard navigating
23+
},
24+
onHide () {
25+
$dropdown.dropdown('set selected', $dropdown.attr('data-last-value')); // restore the really selected value
1826
}
1927
});
2028
}

0 commit comments

Comments
 (0)