mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Convert <div class="button"> to <button class="button"> (#23337)
				
					
				
			This improves a lot of accessibility shortcomings. Every possible instance of `<div class="button">` matching the command `ag '<[^ab].*?class=.*?[" ]button[ "]' templates/ | grep -v 'dropdown'` has been converted when possible. divs with the `dropdown` class and their children were omitted as 1. more analysis must be conducted whether the dropdowns still work as intended when they are a `button` instead of a `div`. 2. most dropdowns have `div`s as children. The HTML standard disallows `div`s inside `button`s. 3. When a dropdown child that's part of the displayed text content is converted to a `button`, the dropdown can be focused twice Further changes include that all "gitea-managed" buttons with JS code received an `e.preventDefault()` so that they don't accidentally submit an underlying form, which would execute instead of cancel the action. Lastly, some minor issues were fixed as well during the refactoring. ## Future improvements As mentioned in https://github.com/go-gitea/gitea/pull/23337#discussion_r1127277391, `<a>`s without `href` attribute are not focusable. They should later on be converted to `<button>`s. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -202,7 +202,8 @@ export function initGlobalDropzone() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function initGlobalLinkActions() {
 | 
			
		||||
  function showDeletePopup() {
 | 
			
		||||
  function showDeletePopup(e) {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    const $this = $(this);
 | 
			
		||||
    const dataArray = $this.data();
 | 
			
		||||
    let filter = '';
 | 
			
		||||
@@ -243,10 +244,10 @@ export function initGlobalLinkActions() {
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }).modal('show');
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function showAddAllPopup() {
 | 
			
		||||
  function showAddAllPopup(e) {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    const $this = $(this);
 | 
			
		||||
    let filter = '';
 | 
			
		||||
    if ($this.attr('id')) {
 | 
			
		||||
@@ -272,7 +273,6 @@ export function initGlobalLinkActions() {
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }).modal('show');
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function linkAction(e) {
 | 
			
		||||
@@ -318,13 +318,21 @@ export function initGlobalLinkActions() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function initGlobalButtons() {
 | 
			
		||||
  $('.show-panel.button').on('click', function () {
 | 
			
		||||
  // There are many "cancel button" elements in modal dialogs, Fomantic UI expects they are button-like elements but never submit a form.
 | 
			
		||||
  // However, Gitea misuses the modal dialog and put the cancel buttons inside forms, so we must prevent the form submission.
 | 
			
		||||
  // There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
 | 
			
		||||
  $(document).on('click', 'form .ui.cancel.button', (e) => {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $('.show-panel.button').on('click', function (e) {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    showElem($(this).data('panel'));
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $('.hide-panel.button').on('click', function (event) {
 | 
			
		||||
  $('.hide-panel.button').on('click', function (e) {
 | 
			
		||||
    // a `.hide-panel.button` can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    let sel = $(this).attr('data-panel');
 | 
			
		||||
    if (sel) {
 | 
			
		||||
      hideElem($(sel));
 | 
			
		||||
@@ -339,7 +347,8 @@ export function initGlobalButtons() {
 | 
			
		||||
    alert('Nothing to hide');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $('.show-modal').on('click', function () {
 | 
			
		||||
  $('.show-modal').on('click', function (e) {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    const modalDiv = $($(this).attr('data-modal'));
 | 
			
		||||
    for (const attrib of this.attributes) {
 | 
			
		||||
      if (!attrib.name.startsWith('data-modal-')) {
 | 
			
		||||
@@ -360,7 +369,8 @@ export function initGlobalButtons() {
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  $('.delete-post.button').on('click', function () {
 | 
			
		||||
  $('.delete-post.button').on('click', function (e) {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
    const $this = $(this);
 | 
			
		||||
    $.post($this.attr('data-request-url'), {
 | 
			
		||||
      _csrf: csrfToken
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user