1
0
Fork 0
forked from forgejo/forgejo

Improve accessibility when (re-)viewing files (#24817)

Visually, nothing should have changed.
Changes include
- Convert most `<a [no href]>` to `<button>` when (re-)viewing files:
- `<a [no href]>` are, by HTML definition, not a link and hence cannot
be focused
- `<a class="ui button">` can now be clicked (again?) using
<kbd>Enter</kbd>
- Previously, the installed keypress handler on `.ui.button` elements
disabled it for links somehow
- The `(un)escape file`, the `expand section` and the `expand/collapse
file` buttons can now be focused (and subsequently clicked using only
the keyboard)
- You can now press <kbd>Space</kbd> on a focused `View file` checkbox
to mark the file as viewed.
- previously, this was impossible as this checkbox listened on the wrong
event listener

The `add code comment` button has been left inaccessible for now as it
requires quite a bit of extra logic so that it is unhidden when it is
focused (you can otherwise focus it without seeing it as you are not
hovering on the corresponding line).

---------

Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
delvh 2023-05-21 22:47:41 +02:00 committed by GitHub
parent c59a057297
commit e95b42e187
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 105 additions and 92 deletions

View file

@ -56,9 +56,8 @@ export function initGlobalEnterQuickSubmit() {
}
export function initGlobalButtonClickOnEnter() {
$(document).on('keypress', '.ui.button', (e) => {
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
if (e.target.nodeName === 'BUTTON') return; // button already handles space&enter correctly
$(document).on('keypress', 'div.ui.button,span.ui.button', (e) => {
if (e.code === ' ' || e.code === 'Enter') {
$(e.target).trigger('click');
e.preventDefault();
}

View file

@ -38,7 +38,7 @@ export function initViewedCheckboxListenerFor() {
// The checkbox consists of a div containing the real checkbox with its label and the CSRF token,
// hence the actual checkbox first has to be found
const checkbox = form.querySelector('input[type=checkbox]');
checkbox.addEventListener('change', function() {
checkbox.addEventListener('input', function() {
// Mark the file as viewed visually - will especially change the background
if (this.checked) {
form.classList.add(viewedStyleClass);

View file

@ -181,7 +181,7 @@ export function initRepoCodeView() {
$(document).on('click', '.fold-file', ({currentTarget}) => {
invertFileFolding(currentTarget.closest('.file-content'), currentTarget);
});
$(document).on('click', '.blob-excerpt', async ({currentTarget}) => {
$(document).on('click', '.code-expander-button', async ({currentTarget}) => {
const url = currentTarget.getAttribute('data-url');
const query = currentTarget.getAttribute('data-query');
const anchor = currentTarget.getAttribute('data-anchor');

View file

@ -62,9 +62,9 @@ function initRepoDiffConversationForm() {
$form.closest('.conversation-holder').replaceWith($newConversationHolder);
if ($form.closest('tr').data('line-type') === 'same') {
$(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).addClass('invisible');
$(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).addClass('invisible');
} else {
$(`[data-path="${path}"] a.add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
$(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
}
$newConversationHolder.find('.dropdown').dropdown();
initCompReactionSelector($newConversationHolder);

View file

@ -177,9 +177,9 @@ export function initRepoIssueCommentDelete() {
const idx = $conversationHolder.data('idx');
const lineType = $conversationHolder.closest('tr').data('line-type');
if (lineType === 'same') {
$(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).removeClass('invisible');
$(`[data-path="${path}"] .add-code-comment[data-idx="${idx}"]`).removeClass('invisible');
} else {
$(`[data-path="${path}"] a.add-code-comment[data-side="${side}"][data-idx="${idx}"]`).removeClass('invisible');
$(`[data-path="${path}"] .add-code-comment[data-side="${side}"][data-idx="${idx}"]`).removeClass('invisible');
}
$conversationHolder.remove();
}
@ -488,7 +488,7 @@ export function initRepoPullRequestReview() {
});
}
$(document).on('click', 'a.add-code-comment', async function (e) {
$(document).on('click', '.add-code-comment', async function (e) {
if ($(e.target).hasClass('btn-add-single')) return; // https://github.com/go-gitea/gitea/issues/4745
e.preventDefault();

View file

@ -2,30 +2,30 @@ import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';
export function initUnicodeEscapeButton() {
$(document).on('click', 'a.escape-button', (e) => {
$(document).on('click', '.escape-button', (e) => {
e.preventDefault();
$(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').addClass('unicode-escaped');
hideElem($(e.target));
showElem($(e.target).siblings('a.unescape-button'));
showElem($(e.target).siblings('.unescape-button'));
});
$(document).on('click', 'a.unescape-button', (e) => {
$(document).on('click', '.unescape-button', (e) => {
e.preventDefault();
$(e.target).parents('.file-content, .non-diff-file-content').find('.file-code, .file-view').removeClass('unicode-escaped');
hideElem($(e.target));
showElem($(e.target).siblings('a.escape-button'));
showElem($(e.target).siblings('.escape-button'));
});
$(document).on('click', 'a.toggle-escape-button', (e) => {
$(document).on('click', '.toggle-escape-button', (e) => {
e.preventDefault();
const fileContent = $(e.target).parents('.file-content, .non-diff-file-content');
const fileView = fileContent.find('.file-code, .file-view');
if (fileView.hasClass('unicode-escaped')) {
fileView.removeClass('unicode-escaped');
hideElem(fileContent.find('a.unescape-button'));
showElem(fileContent.find('a.escape-button'));
hideElem(fileContent.find('.unescape-button'));
showElem(fileContent.find('.escape-button'));
} else {
fileView.addClass('unicode-escaped');
showElem(fileContent.find('a.unescape-button'));
hideElem(fileContent.find('a.escape-button'));
showElem(fileContent.find('.unescape-button'));
hideElem(fileContent.find('.escape-button'));
}
});
}