Skip to content

Commit

Permalink
Convert <div class="button"> to <button class="button"> (go-gitea…
Browse files Browse the repository at this point in the history
…#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
go-gitea#23337 (comment),
`<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>
  • Loading branch information
5 people committed Mar 14, 2023
1 parent 605fd15 commit 81fe5d6
Show file tree
Hide file tree
Showing 57 changed files with 173 additions and 283 deletions.
1 change: 1 addition & 0 deletions public/img/svg/fontawesome-save.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion templates/admin/auth/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@

<div class="field">
<button class="ui green button">{{.locale.Tr "admin.auths.update"}}</button>
<div class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.Source.ID}}">{{.locale.Tr "admin.auths.delete"}}</div>
<button class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.Source.ID}}">{{.locale.Tr "admin.auths.delete"}}</button>
</div>
</form>
</div>
Expand Down
8 changes: 3 additions & 5 deletions templates/admin/emails/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{{.locale.Tr "admin.emails.change_email_header"}}
</div>
<div class="content center">
<p>{{.locale.Tr "admin.emails.change_email_text"}}</p>
<p class="center">{{.locale.Tr "admin.emails.change_email_text"}}</p>

<form class="ui form" id="email-action-form" action="{{AppSubUrl}}/admin/emails/activate" method="post">
{{$.CsrfTokenHtml}}
Expand All @@ -93,11 +93,9 @@
<input type="hidden" id="form-primary" name="primary" value="" required>
<input type="hidden" id="form-activate" name="activate" value="" required>

<div class="center actions">
<div class="ui basic cancel inverted button">{{$.locale.Tr "settings.cancel"}}</div>
<button class="ui basic inverted yellow button">{{$.locale.Tr "modal.yes"}}</button>
<div class="center">
{{template "base/delete_modal_actions" .}}
</div>

</form>
</div>
</div>
Expand Down
18 changes: 8 additions & 10 deletions templates/admin/notice.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<tr>
<td class="collapsing">
<div class="ui fitted checkbox" data-id="{{.ID}}">
<input type="checkbox"> <label></label>
<input type="checkbox">
</div>
</td>
<td>{{.ID}}</td>
Expand All @@ -39,13 +39,11 @@
<tr>
<th></th>
<th colspan="5">
<div class="ui right">
<form method="post" action="{{AppSubUrl}}/admin/notices/empty">
{{.CsrfTokenHtml}}
<button type="submit" class="ui red small button">{{.locale.Tr "admin.notices.delete_all"}}</button>
</form>
</div>
<div class="ui floating upward dropdown small button">
<form class="ui right" method="post" action="{{AppSubUrl}}/admin/notices/empty">
{{.CsrfTokenHtml}}
<button type="submit" class="ui red small button">{{.locale.Tr "admin.notices.delete_all"}}</button>
</form>
<div class="ui floating upward dropdown small button">{{/* TODO: Make this dropdown accessible */}}
<span class="text">{{.locale.Tr "admin.notices.operations"}}</span>
<div class="menu">
<div class="item select action" data-action="select-all">
Expand All @@ -59,9 +57,9 @@
</div>
</div>
</div>
<div class="ui small teal button" id="delete-selection" data-link="{{.Link}}/delete" data-redirect="{{.Link}}?page={{.Page.Paginater.Current}}">
<button class="ui small teal button" id="delete-selection" data-link="{{.Link}}/delete" data-redirect="{{.Link}}?page={{.Page.Paginater.Current}}">
{{.locale.Tr "admin.notices.delete_selected"}}
</div>
</button>
</th>
</tr>
</tfoot>
Expand Down
22 changes: 2 additions & 20 deletions templates/admin/repo/unadopted.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@
<input type="hidden" name="action" value="adopt">
<input type="hidden" name="q" value="{{$.Keyword}}">
<input type="hidden" name="page" value="{{$.CurrentPage}}">
<div class="actions">
<div class="ui red basic inverted cancel button">
{{svg "octicon-trash" 16 "gt-mr-2"}}
{{$.locale.Tr "modal.no"}}
</div>
<button class="ui green basic inverted ok button">
{{svg "octicon-check" 16 "gt-mr-2"}}
{{$.locale.Tr "modal.yes"}}
</button>
</div>
{{template "base/delete_modal_actions" .}}
</form>
</div>
<button class="ui button submit tiny red delete show-modal" data-modal="#delete-unadopted-modal-{{$dirI}}"><span class="icon">{{svg "octicon-x"}}</span><span class="label">{{$.locale.Tr "repo.delete_preexisting_label"}}</span></button>
Expand All @@ -70,16 +61,7 @@
<input type="hidden" name="action" value="delete">
<input type="hidden" name="q" value="{{$.Keyword}}">
<input type="hidden" name="page" value="{{$.CurrentPage}}">
<div class="actions">
<div class="ui red basic inverted cancel button">
{{svg "octicon-trash" 16 "gt-mr-2"}}
{{$.locale.Tr "modal.no"}}
</div>
<button class="ui green basic inverted ok button">
{{svg "octicon-check" 16 "gt-mr-2"}}
{{$.locale.Tr "modal.yes"}}
</button>
</div>
{{template "base/delete_modal_actions" .}}
</form>
</div>
</div>
Expand Down
15 changes: 3 additions & 12 deletions templates/admin/user/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

<div class="field">
<button class="ui green button">{{.locale.Tr "admin.users.update_profile"}}</button>
<div class="ui red button show-modal" data-modal="#delete-user-modal">{{.locale.Tr "admin.users.delete_account"}}</div>
<button class="ui red button show-modal" data-modal="#delete-user-modal">{{.locale.Tr "admin.users.delete_account"}}</button>
</div>
</form>
</div>
Expand Down Expand Up @@ -189,7 +189,7 @@

<div class="field">
<button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button>
<a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a>
<a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a>{{/* TODO: Convert links without href to buttons for a11y */}}
</div>
</form>
</div>
Expand All @@ -213,16 +213,7 @@
</div>
<p class="help">{{.locale.Tr "admin.users.purge_help"}}</p>
</div>
<div class="actions">
<div class="ui red basic inverted cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "modal.no"}}
</div>
<button class="ui green basic inverted ok button">
{{svg "octicon-check"}}
{{.locale.Tr "modal.yes"}}
</button>
</div>
{{template "base/delete_modal_actions" .}}
</form>
</div>
{{template "base/footer" .}}
8 changes: 4 additions & 4 deletions templates/base/delete_modal_actions.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="actions">
<div class="ui red basic inverted cancel button">
<button class="ui red basic inverted cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "modal.no"}}
</div>
<div class="ui green basic inverted ok button">
</button>
<button class="ui green basic inverted ok button">
{{svg "octicon-check"}}
{{.locale.Tr "modal.yes"}}
</div>
</button>
</div>
4 changes: 2 additions & 2 deletions templates/org/settings/delete.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<label for="org_name">{{.locale.Tr "org.org_name_holder"}}</label>
<input id="org_name" name="org_name" value="" autocomplete="off" autofocus required>
</div>
<div class="ui red button delete-button" data-type="form" data-form="#delete-form">
<button class="ui red button delete-button" data-type="form" data-form="#delete-form">
{{.locale.Tr "org.settings.confirm_delete_account"}}
</div>
</button>
</form>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/org/settings/labels.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="right floated three wide column">
<div class="ui right">
<div class="ui green new-label button">{{.locale.Tr "repo.issues.new_label"}}</div>
<button class="ui green new-label button">{{.locale.Tr "repo.issues.new_label"}}</button>
</div>
</div>
</div>
Expand Down
5 changes: 1 addition & 4 deletions templates/package/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="delete">
<div class="text right actions">
<div class="ui cancel button">{{.locale.Tr "cancel"}}</div>
<button class="ui red button">{{.locale.Tr "ok"}}</button>
</div>
{{template "base/delete_modal_actions" .}}
</form>
</div>
</div>
Expand Down
11 changes: 1 addition & 10 deletions templates/projects/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@
<div class="content">
<p>{{.locale.Tr "repo.projects.deletion_desc"}}</p>
</div>
<div class="actions">
<div class="ui red basic inverted cancel button">
<i class="remove icon"></i>
{{.locale.Tr "modal.no"}}
</div>
<div class="ui green basic inverted ok button">
<i class="checkmark icon"></i>
{{.locale.Tr "modal.yes"}}
</div>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{end}}
21 changes: 6 additions & 15 deletions templates/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>

<div class="text right actions">
<div class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button data-url="{{$.Link}}" class="ui primary button" id="new_board_submit">{{$.locale.Tr "repo.projects.column.new_submit"}}</button>
</div>
</form>
Expand Down Expand Up @@ -127,7 +127,7 @@
</div>

<div class="text right actions">
<div class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button data-url="{{$.Link}}/{{.ID}}" class="ui primary button edit-column-button">{{$.locale.Tr "repo.projects.column.edit"}}</button>
</div>
</form>
Expand All @@ -144,7 +144,7 @@
</label>
</div>
<div class="text right actions">
<div class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button class="ui primary button set-default-project-board" data-url="{{$.Link}}/{{.ID}}/default">{{$.locale.Tr "repo.projects.column.set_default"}}</button>
</div>
</div>
Expand All @@ -158,8 +158,8 @@
{{$.locale.Tr "repo.projects.column.deletion_desc"}}
</label>
</div>
<div class="text right actions">
<div class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</div>
<div class="text right actions">{{/* TODO: convert to base/delete_modal_actions.tmpl */}}
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button class="ui red button delete-project-board" data-url="{{$.Link}}/{{.ID}}">{{$.locale.Tr "repo.projects.column.delete"}}</button>
</div>
</div>
Expand Down Expand Up @@ -265,15 +265,6 @@
<div class="content">
<p>{{.locale.Tr "repo.projects.deletion_desc"}}</p>
</div>
<div class="actions">
<div class="ui red basic inverted cancel button">
<i class="remove icon"></i>
{{.locale.Tr "modal.no"}}
</div>
<div class="ui green basic inverted ok button">
<i class="checkmark icon"></i>
{{.locale.Tr "modal.yes"}}
</div>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{end}}
2 changes: 1 addition & 1 deletion templates/repo/branch/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
</div>

<div class="text right actions">
<div class="ui cancel button">{{.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{.locale.Tr "settings.cancel"}}</button>
<button class="ui green button">{{.locale.Tr "repo.branch.confirm_create_branch"}}</button>
</div>
</form>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/cite/cite_modal.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</div>
</div>
<div class="actions">
<div class="ui black deny button">
<button class="ui black cancel button">
{{.locale.Tr "cancel"}}
</div>
</button>
</div>
</div>
4 changes: 2 additions & 2 deletions templates/repo/commit_page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</div>

<div class="text right actions">
<div class="ui cancel button">{{.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{.locale.Tr "settings.cancel"}}</button>
<button class="ui green button">{{.locale.Tr "repo.branch.confirm_create_branch"}}</button>
</div>
</form>
Expand All @@ -121,7 +121,7 @@
</div>

<div class="text right actions">
<div class="ui cancel button">{{.locale.Tr "settings.cancel"}}</div>
<button class="ui cancel button">{{.locale.Tr "settings.cancel"}}</button>
<button class="ui green button">{{.locale.Tr "repo.tag.confirm_create_tag"}}</button>
</div>
</form>
Expand Down
8 changes: 4 additions & 4 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
<div class="diff-file-header-actions gt-df gt-ac">
{{if $showFileViewToggle}}
<div class="ui compact icon buttons">
<span class="ui tiny basic button tooltip file-view-toggle" data-toggle-selector="#diff-source-{{$file.NameHash}}" data-content="{{$.locale.Tr "repo.file_view_source"}}" data-position="bottom center">{{svg "octicon-code"}}</span>
<span class="ui tiny basic button tooltip file-view-toggle active" data-toggle-selector="#diff-rendered-{{$file.NameHash}}" data-content="{{$.locale.Tr "repo.file_view_rendered"}}" data-position="bottom center">{{svg "octicon-file"}}</span>
<button class="ui tiny basic button tooltip file-view-toggle" data-toggle-selector="#diff-source-{{$file.NameHash}}" data-content="{{$.locale.Tr "repo.file_view_source"}}" data-position="bottom center">{{svg "octicon-code"}}</button>
<button class="ui tiny basic button tooltip file-view-toggle active" data-toggle-selector="#diff-rendered-{{$file.NameHash}}" data-content="{{$.locale.Tr "repo.file_view_rendered"}}" data-position="bottom center">{{svg "octicon-file"}}</button>
</div>
{{end}}
{{if $file.IsProtected}}
Expand Down Expand Up @@ -200,8 +200,8 @@
{{$.locale.Tr "loading"}}
</div>
<div class="text right edit buttons">
<div class="ui basic primary cancel button" tabindex="3">{{.locale.Tr "repo.issues.cancel"}}</div>
<div class="ui green save button" tabindex="2">{{.locale.Tr "repo.issues.save"}}</div>
<button class="ui basic primary cancel button" tabindex="3">{{.locale.Tr "repo.issues.cancel"}}</button>
<button class="ui green save button" tabindex="2">{{.locale.Tr "repo.issues.save"}}</button>
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/repo/editor/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
<p>{{.locale.Tr "repo.editor.commit_empty_file_text"}}</p>
</div>
<div class="actions">
<div class="ui red basic cancel inverted button">
<button class="ui red basic cancel inverted button">
<i class="remove icon"></i>
{{.locale.Tr "repo.editor.cancel"}}
</div>
<div class="ui green basic ok inverted button">
</button>
<button class="ui green basic ok inverted button">
<i class="save icon"></i>
{{.locale.Tr "repo.editor.commit_changes"}}
</div>
</button>
</div>
</div>

Expand Down
12 changes: 6 additions & 6 deletions templates/repo/editor/patch.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
<p>{{.locale.Tr "repo.editor.commit_empty_file_text"}}</p>
</div>
<div class="actions">
<div class="ui red basic cancel inverted button">
<i class="remove icon"></i>
<button class="ui red basic inverted cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "repo.editor.cancel"}}
</div>
<div class="ui green basic ok inverted button">
<i class="save icon"></i>
</button>
<button class="ui green basic inverted ok button">
{{svg "fontawesome-save"}}
{{.locale.Tr "repo.editor.commit_changes"}}
</div>
</button>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/labels.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{template "repo/issue/navbar" .}}
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
<div class="ui right">
<div class="ui green new-label button">{{.locale.Tr "repo.issues.new_label"}}</div>
<button class="ui green new-label button">{{.locale.Tr "repo.issues.new_label"}}</button>
</div>
{{end}}
</div>
Expand Down
Loading

0 comments on commit 81fe5d6

Please sign in to comment.