Skip to content

Enable RTL support for all inputs and textareas #26715

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

Closed
wants to merge 21 commits into from

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Aug 24, 2023

Result of

perl -p -i -e 's#<textarea #<textarea dir="auto" #g' templates/**/* web_src/js/**/*.{js,vue}
perl -p -i -e 's#<input #<input dir="auto" #g' templates/**/* web_src/js/**/*.{js,vue}

There are likely a few superflous replacements, we need to review diff carefully.

Screenshot 2023-08-24 at 20 39 51 Screenshot 2023-08-24 at 20 46 13 Screenshot 2023-08-24 at 20 46 27

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 24, 2023
@silverwind silverwind added the type/enhancement An improvement of existing functionality label Aug 24, 2023
@silverwind
Copy link
Member Author

silverwind commented Aug 24, 2023

I'm inclined to not fix the cases of hidden inputs or comments, just to reinforce that this attribute should always be set.

BTW, this is a prime example why a shared/input template would be good. Change would be 1 line instead of 900+ :)

@yekanchi
Copy link

خیلی ممنون.
کارتون عالیه!

@silverwind
Copy link
Member Author

I think I'll actually do a pass and remove it from all inputs where type is hidden,checkbox,file. Any other types I missed?

@silverwind
Copy link
Member Author

silverwind commented Aug 24, 2023

Actually it does work on type=file.

image

I think this is good to go. The extra work to remove the dir attribute on types checkbox and hidden seems not worth it.

Copy link
Member

@yardenshoham yardenshoham left a comment

Choose a reason for hiding this comment

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

נראה מעולה, תודה רבה!

@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 Aug 24, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 25, 2023

Haven't read code or thought about it carefully.

But I have a question about whether this approach is good enough: for future PRs, will there always be a person who are able to keep telling contributors "please add dir=auto" again and again?


Some more thoughts:

  1. Maybe MutationObserver is a good use case for it. Just add "dir=auto" automtically for all input/textarea elements.
  2. If it would use "{{template "shared/input ....}}", there must be a lint rule to forbid the <input> in code, and it still has down side: it can't handle backend generated HTML / JS code / Vue component automatically.

@silverwind
Copy link
Member Author

silverwind commented Aug 25, 2023

I think best we can do is watch out for these in review. MutationObserver might be something to consider too, yes.

I don't think djilint supports forbiding certain elements, but it'd be a nice feature to have.

@silverwind silverwind added this to the 1.21.0 milestone Aug 25, 2023
@wxiaoguang
Copy link
Contributor

I think best we can do is watch out for these in review. MutationObserver might be something to consider too, yes.

Would you like to take a try? Or I could try too. TBH, keeping asking contributors to add "dir=auto" doesn't look good to me.

@silverwind
Copy link
Member Author

silverwind commented Aug 25, 2023

Not interested right now, this PR should be a simple attribute addition.

I will do one pass to remove it from hidden and checkbox just for the sake of it being useless there. That alone is already a lot of work with over 500 matches.

I think it's ideal to be correct without any JS involved.

@wxiaoguang
Copy link
Contributor

Not interested right now, this PR should be a simple attribute addition.

I will try to propose a MutationObserver solution. If there is no performance problem, I think that's the once and for all solution.

@silverwind
Copy link
Member Author

Ready to review/merge now, diff is down to half after hidden/checkbox removal.

@wxiaoguang
Copy link
Contributor

Ready to review/merge now, diff is down to half after hidden/checkbox removal.

Could we wait for more time? I do not think keeping adding attributes manually is maintainable.

@silverwind
Copy link
Member Author

silverwind commented Aug 25, 2023

I will try to propose a MutationObserver solution. If there is no performance problem, I think that's the once and for all solution.

Try that I guess. Sadly it means RTL won't work without JS, but it would be the more maintainable solution via JS.

@wxiaoguang
Copy link
Contributor

Sadly it means RTL won't work without JS

Gitea UI already doesn't work without JS for long time.

@silverwind silverwind marked this pull request as draft August 25, 2023 17:43
@silverwind
Copy link
Member Author

Well I blame it on the browser vendors for not making this attribute the default. Maybe they will see the light someday and we can remove the JS then.

@wxiaoguang
Copy link
Contributor

-> Add "dir=auto" for input/textarea elements by default #26735

@silverwind
Copy link
Member Author

#26735 has non-neglible performance impact, I think this solution is better. We don't have to meticulously have dir=auto on every element. For example GitHub only very rarely adds it, like on this Textarea.

@silverwind silverwind marked this pull request as ready for review August 25, 2023 19:29
@silverwind
Copy link
Member Author

So I think I'm definitely done here, checked the diff twice, it's now down to +399 −398.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Aug 26, 2023

#26735 has been fully rewritten, now it takes around 1.5ms on a PR page with +6966 -3615 (the rendered changed lines is around 3000)

@silverwind
Copy link
Member Author

silverwind commented Aug 26, 2023

IDK, maybe we should just do it for the single markup textarea and be done with it, it seems that's exactly what GitHub is doing. Possibly all textareas.

@silverwind
Copy link
Member Author

Closing in favor of #26735

@silverwind silverwind closed this Sep 6, 2023
@silverwind silverwind deleted the rtli branch September 6, 2023 20:33
@GiteaBot GiteaBot removed this from the 1.21.0 milestone Sep 7, 2023
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants