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

Band-aid solution to make edit buttons focusable #19922

Closed

Conversation

Ryuno-Ki
Copy link
Contributor

@Ryuno-Ki Ryuno-Ki commented Jun 8, 2022

Partially addressing #19769

These will need more work to get done properly.
However, this will require more communication, which might mean
that a fix may or may not make it into the next release.

To improve the situation at least a little bit, allow for
keyboard usage.

I noticed that the :focus styling is lost on the cancel button here.
Inspecting the root cause led to a regression caused by #19763
I'd like to have @silverwind look into this if possible, as I lack the
context that led to the mentioned PR. (namely: why !importants?)

Regarding the usage of <div>s: That was never changed here.
I would assume, there is no specific reason. Should I change the
markup to a proper <button type="button"> instead? Or are there
side effects I should be aware of?

Signed-off-by: André Jaenisch [email protected]

These will need more work to get done properly.
However, this will require more communication, which might mean
that a fix may or may not make it into the next release.

To improve the situation at least a little bit, allow for
keyboard usage.

Signed-off-by: André Jaenisch <[email protected]>
@delvh
Copy link
Member

delvh commented Jun 8, 2022

Regarding the usage of <div>s: That was never changed here.
I would assume, there is no specific reason. Should I change the
markup to a proper <button type="button"> instead? Or are there
side effects I should be aware of?

As @silverwind once told me:

Keep it simple. If something is not a <button>, it will have a11y problems and should be changed to such.

So it is most likely unintended that they are not buttons.
But keep one thing in mind:

According to my quick search (ag 'class=".*button.*"' | grep -v '<button' | wc -l), there are 335 of those... Have fun fixing all of them.

(Both quotes have been copied from #19330)

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 8, 2022
@silverwind
Copy link
Member

silverwind commented Jun 8, 2022

I noticed that the :focus styling is lost on the cancel button here.

Probably just an oversight. Suggesting to add this CSS to restore/improve focus/hover styles. !important is to ensure it override fomantic's styles):

.ui.basic.secondary.buttons .button:hover,
.ui.basic.secondary.button:hover,
.ui.basic.secondary.buttons .button:active,
.ui.basic.secondary.button:active {
  color: var(--color-secondary-dark-8) !important;
  border-color: var(--color-secondary-dark-4) !important;
}

.ui.basic.secondary.button:focus,
.ui.basic.secondary.buttons .button:focus {
  color: var(--color-secondary-dark-8) !important;
  border-color: var(--color-secondary-dark-6) !important;
}

Should I change the
markup to a proper instead? Or are there
side effects I should be aware of?

Yes, <button> would be preferred (not sure if type is needed) and it's better for accessibilty too. If it works, go ahead. You might need to change some JS selectors.

@Ryuno-Ki
Copy link
Contributor Author

Ryuno-Ki commented Jun 8, 2022

Thank you for the quick response.
The evening is already late here, so I will update my PR in the next days (likely tomorrow).

@wxiaoguang
Copy link
Contributor

According to https://fomantic-ui.com/elements/button.html

Could these code be used instead of role or div?

<button class="ui primary basic button">Primary</button>
<button class="ui secondary basic button">Secondary</button>
<button class="ui positive basic button">Positive</button>
<button class="ui negative basic button">Negative</button>

@silverwind
Copy link
Member

According to https://fomantic-ui.com/elements/button.html

Could these code be used instead of role or div?

<button class="ui primary basic button">Primary</button>
<button class="ui secondary basic button">Secondary</button>
<button class="ui positive basic button">Positive</button>
<button class="ui negative basic button">Negative</button>

Yes that will work. role=button is unnecessary on <button>, the only case where it should be used is <a role="button">.

@silverwind
Copy link
Member

BTW I think if you make it a <button>, adding tabindex will no longer be necessary as the element is naturally focusable then.

The only downside I observed is that cancel button accepts only
space keys. Using return will execute the logic twice for whatever
reason and thus yields in no visible change.

Signed-off-by: André Jaenisch <[email protected]>
@Ryuno-Ki
Copy link
Contributor Author

Took me a while longer (managing three kids during holidays is stressful, let me tell you …).

@delvh

Have fun fixing all of them.

That is another opportunity to onboard contributors :-)

@silverwind

Suggesting to add this CSS to restore/improve focus/hover styles.

Thanks, picked them up and included them. I also removed the tabindex.

Could these code be used instead of role or div?

They could and they should.
<button> naturally have an implicit aria-role="button", so should not be added.
Using anything else would require to implement these patterns: https://www.w3.org/WAI/ARIA/apg/patterns/button/

@Ryuno-Ki
Copy link
Contributor Author

While testing 5f999d8 manually I observed, that the cancel button seem not to react to return presses. It did that before.

Debugging it yielded that the registered event handler gets executed twice (spacebar only once). I was not able to fix that.

@@ -14,8 +14,8 @@
</h1>
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .Repository.IsArchived)}}
<div class="edit-buttons">
<div id="cancel-edit-title" class="ui basic secondary in-edit button" style="display: none">{{.i18n.Tr "repo.issues.cancel"}}</div>
<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}}>{{.i18n.Tr "repo.issues.save"}}</div>
<button id="cancel-edit-title" class="ui basic secondary in-edit button" style="display: none" type="button">{{.i18n.Tr "repo.issues.cancel"}}</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be shorten to:

Suggested change
<button id="cancel-edit-title" class="ui basic secondary in-edit button" style="display: none" type="button">{{.i18n.Tr "repo.issues.cancel"}}</button>
<button id="cancel-edit-title" class="ui basic secondary in-edit button" hidden>{{.i18n.Tr "repo.issues.cancel"}}</button>

And there is a similar <div class=button> on line 5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How strong do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would choose the better / more ideal solutions as much as possible.

Since these code is being refactored and these buttons (including the line 5) work together, so they could be improved together.

@wxiaoguang
Copy link
Contributor

While testing 5f999d8 manually I observed, that the cancel button seem not to react to return presses. It did that before.

Debugging it yielded that the registered event handler gets executed twice (spacebar only once). I was not able to fix that.

Maybe related to the legacy code (which is not ideal ....)

export function initGlobalButtonClickOnEnter() {
$(document).on('keypress', '.ui.button', (e) => {
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
$(e.target).trigger('click');
}
});
}

@Ryuno-Ki
Copy link
Contributor Author

Maybe related to the legacy code (which is not ideal ....)

I would expect the same behaviour before then as well. But it was executed only once with the <div> implementation.

@wxiaoguang
Copy link
Contributor

Maybe related to the legacy code (which is not ideal ....)

I would expect the same behaviour before then as well. But it was executed only once with the <div> implementation.

Yes, because the button has a native event handler for Enter. So the Enter will trigger the native event handler and the customized event handler -- twice.

techknowlogick added a commit that referenced this pull request Feb 9, 2023
…ts (#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 <[email protected]>
@wxiaoguang
Copy link
Contributor

Replaced by #22807

@lunny lunny closed this Feb 10, 2023
@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/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants