Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert <div class="button"> to <button class="button"> #23337

Merged
merged 10 commits into from Mar 14, 2023

Conversation

delvh
Copy link
Member

@delvh delvh commented Mar 6, 2023

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 divs as children. The HTML standard disallows divs inside buttons.
  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 #23337 (comment), <a>s without href attribute are not focusable.
They should later on be converted to <button>s.

This improves a lot of accessibility shortcomings.
Every possible instance matching the command
`ag '<[^ab].*?class=.*?[" ]button[ "]' templates/ | grep -v 'dropdown'`
has been converted when possible.
Furthermore, all `cancel` buttons received `type="button"` so that they
don't accidentally trigger an underlying form.
Lastly, some small and minor issues were fixed as well while
refactoring.
@delvh delvh added the topic/accessibility This issue/pull request wants to improve the accessibility label Mar 6, 2023
@delvh delvh added this to the 1.20.0 milestone Mar 6, 2023
@delvh delvh added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Mar 6, 2023
@codecov-commenter

This comment was marked as off-topic.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 6, 2023
templates/repo/activity.tmpl Outdated Show resolved Hide resolved
templates/admin/notice.tmpl Show resolved Hide resolved
templates/admin/user/edit.tmpl Outdated Show resolved Hide resolved
templates/base/delete_modal_actions.tmpl Outdated Show resolved Hide resolved
templates/admin/notice.tmpl Show resolved Hide resolved
templates/admin/user/edit.tmpl Outdated Show resolved Hide resolved
Most notably, this includes automatically setting 'type="button"' for
all cancel buttons,
and 'e.preventDefault()' when opening a modal.
delvh and others added 2 commits March 13, 2023 21:07
Additionally, prevent the default event propagation for all buttons with
JS, convert `event` to `e` in `web_src/js/features/common-global.js` for consistency
and add fontawesome-save svg.

Closes #2

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
@delvh
Copy link
Member Author

delvh commented Mar 13, 2023

@wxiaoguang @silverwind all done.
@remaining maintainers ping - this PR exists, and apparently it is already holding back some other PRs.

@wxiaoguang
Copy link
Contributor

According to https://github.com/go-gitea/gitea/blob/main/docs/content/doc/developers/guidelines-refactoring.en-us.md

If there is no objection from TOC, a refactoring PR could be merged after 7 days with one core member's approval (not the author).

😆

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 13, 2023
@techknowlogick
Copy link
Member

According to https://github.com/go-gitea/gitea/blob/main/docs/content/doc/developers/guidelines-refactoring.en-us.md

If there is no objection from TOC, a refactoring PR could be merged after 7 days with one core member's approval (not the author).

Indeed, we have now met that criteria with my +1. I will let someone else be the merger on this, although I suspect with branch rules it'll need to be a TOC member who can use 🧙 powers. Of course, if it doesn't get merged in enough time I can be the merger if needed (please ping if that is the case).

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 13, 2023
@delvh delvh added reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. outdated/backport/v1.19 This PR should be backported to Gitea 1.19 labels Mar 13, 2023
@lunny lunny merged commit 81fe5d6 into go-gitea:main Mar 14, 2023
@lunny lunny removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 14, 2023
@GiteaBot
Copy link
Contributor

I was unable to create a backport for 1.19, please send one manually. 🍵

@GiteaBot GiteaBot added the backport/manual No power to the bots! Create your backport yourself! label Mar 14, 2023
@wxiaoguang
Copy link
Contributor

Does this PR really need to be backported? I am a little worried about whether it would break something, because the button behavior / focus behavior change more or less. Keep it in 1.20 for long enough time before backport?

@wxiaoguang
Copy link
Contributor

Caught one 500 (not sure whether it's related)

http://localhost:3000/user/settings/repos

template: base/delete_modal_actions:4:11: executing "base/delete_modal_actions" at <.locale.Tr>: can't evaluate field locale in type string

@delvh delvh removed outdated/backport/v1.19 This PR should be backported to Gitea 1.19 backport/manual No power to the bots! Create your backport yourself! labels Mar 14, 2023
@delvh delvh deleted the feature/convert-divs-to-button branch March 14, 2023 09:24
delvh added a commit that referenced this pull request Mar 21, 2023
Caught by @wxiaoguang in
#23337 (comment).

Additionally, there were three instances that have the same content as `templates/base/deletion_modal_actions.tmpl` but that are not intended to delete something.
Instead of renaming the template above, these instances were simply re-hard-coded again.
Renaming/improving the template above is left for future PRs.
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/accessibility This issue/pull request wants to improve the accessibility type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants