Skip to content

Commit affdd40

Browse files
Make issue title edit buttons focusable and fix incorrect ajax requests (#22807)
Replace #19922 , which is stale since my last review: #19922 (review) and #19922 (comment) Close #19769 Changes: 1. Use `<button>` instead of `<div>` for buttons 2. Prevent default event handler in `initGlobalButtonClickOnEnter` 3. Fix the incorrect call to `pullrequest_targetbranch_change` 4. Add a slight margin-left to the input element to make UI look better The logic in repo-issue.js is not ideal, but this PR isn't going to touch the logic. This is also an example for future developers to understand how to make buttons work properly. ### Before ![image](https://user-images.githubusercontent.com/2114189/217262515-ec0462f7-7051-46a5-bfa2-2f6c6a807b7d.png) ### After * Add a slight margin-left. * The `Cancel` button is focused. ![image](https://user-images.githubusercontent.com/2114189/217264891-934c9c8d-d190-4866-98b5-666cea57e28d.png) Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent bdd2c9d commit affdd40

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

templates/repo/issue/view_title.tmpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
<div class="issue-title" id="issue-title-wrapper">
33
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .Repository.IsArchived)}}
44
<div class="edit-button">
5-
<div id="edit-title" class="ui basic secondary not-in-edit button">{{.locale.Tr "repo.issues.edit"}}</div>
5+
<button id="edit-title" class="ui basic button secondary not-in-edit">{{.locale.Tr "repo.issues.edit"}}</button>
66
</div>
77
{{end}}
88
<h1>
99
<span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas | RenderCodeBlock}}</span>
1010
<span class="index">#{{.Issue.Index}}</span>
11-
<div id="edit-title-input" class="ui input" style="display: none">
11+
<div id="edit-title-input" class="ui input ml-4" style="display: none">
1212
<input value="{{.Issue.Title}}" maxlength="255" autocomplete="off">
1313
</div>
1414
</h1>
1515
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .Repository.IsArchived)}}
1616
<div class="edit-buttons">
17-
<div id="cancel-edit-title" class="ui basic secondary in-edit button" style="display: none">{{.locale.Tr "repo.issues.cancel"}}</div>
18-
<div id="save-edit-title" class="ui primary in-edit button" style="display: none" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title" {{if .Issue.IsPull}}data-target-update-url="{{$.RepoLink}}/pull/{{.Issue.Index}}/target_branch"{{end}}>{{.locale.Tr "repo.issues.save"}}</div>
17+
<button id="cancel-edit-title" class="ui basic button secondary in-edit" style="display: none">{{.locale.Tr "repo.issues.cancel"}}</button>
18+
<button id="save-edit-title" class="ui primary button in-edit" style="display: none" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title" {{if .Issue.IsPull}}data-target-update-url="{{$.RepoLink}}/pull/{{.Issue.Index}}/target_branch"{{end}}>{{.locale.Tr "repo.issues.save"}}</button>
1919
</div>
2020
{{end}}
2121
</div>

web_src/js/features/common-global.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function initGlobalButtonClickOnEnter() {
6060
$(document).on('keypress', '.ui.button', (e) => {
6161
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
6262
$(e.target).trigger('click');
63+
e.preventDefault();
6364
}
6465
});
6566
}

web_src/js/features/repo-issue.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ export function initRepoIssueTitleEdit() {
605605
const targetBranch = $('#pull-target-branch').data('branch');
606606
const $branchTarget = $('#branch_target');
607607
if (targetBranch === $branchTarget.text()) {
608+
window.location.reload();
608609
return false;
609610
}
610611
$.post(update_url, {
@@ -617,19 +618,22 @@ export function initRepoIssueTitleEdit() {
617618
});
618619
};
619620

620-
const pullrequest_target_update_url = $(this).data('target-update-url');
621+
const pullrequest_target_update_url = $(this).attr('data-target-update-url');
621622
if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) {
622623
$editInput.val($issueTitle.text());
623624
pullrequest_targetbranch_change(pullrequest_target_update_url);
624625
} else {
625-
$.post($(this).data('update-url'), {
626+
$.post($(this).attr('data-update-url'), {
626627
_csrf: csrfToken,
627628
title: $editInput.val()
628629
}, (data) => {
629630
$editInput.val(data.title);
630631
$issueTitle.text(data.title);
631-
pullrequest_targetbranch_change(pullrequest_target_update_url);
632-
window.location.reload();
632+
if (pullrequest_target_update_url) {
633+
pullrequest_targetbranch_change(pullrequest_target_update_url); // it will reload the window
634+
} else {
635+
window.location.reload();
636+
}
633637
});
634638
}
635639
return false;

web_src/less/_base.less

+7
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,13 @@ a.ui.label:hover {
23162316
.ui.basic.secondary.buttons .button:active,
23172317
.ui.basic.secondary.button:active {
23182318
color: var(--color-secondary-dark-8) !important;
2319+
border-color: var(--color-secondary-dark-1) !important;
2320+
}
2321+
2322+
.ui.basic.secondary.button:focus,
2323+
.ui.basic.secondary.buttons .button:focus {
2324+
color: var(--color-secondary-dark-8) !important;
2325+
border-color: var(--color-secondary-dark-3) !important;
23192326
}
23202327

23212328
.ui.tertiary.button {

0 commit comments

Comments
 (0)