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
Add RTL support to Textbox
, Markdown
, Chatbot
#4933
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-4933-all-demos You can install the changes in this PR by running: pip install https://gradio-builds.s3.amazonaws.com/6d40cdc7c516434d498d6b1bf129cfaa1d5a7eb3/gradio-3.36.1-py3-none-any.whl |
🎉 Chromatic build completed! There are 11 visual changes to review. |
I also added a few stories for visual testing of Overall, it was very pleasant to add the visual tests! |
gradio/components/textbox.py
Outdated
@@ -89,6 +91,8 @@ def __init__( | |||
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. | |||
elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. | |||
type: The type of textbox. One of: 'text', 'password', 'email', Default is 'text'. | |||
text_align: How to align the text in the textbox. One of: 'left', 'center', 'right', 'justify'. Default is 'left'. Can only be changed if type=='text'. | |||
rtl: If True and type=='text', sets the direction of the text to right-to-left (text is aligned right, and cursor appears on the left of the text). Takes precendence over the `text_align` parameter. Default is False, which renders cursor on the right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo precedence
|
||
<Story | ||
name="Simple inline Markdown" | ||
args={{ }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i think we can just remove the args param if not in use, it's not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right way to handle rtl, it isn't just about alignment. We should be using dir=rtl
in all of these cases. It is supported by pretty much every element and handles alignment by default.
We will also want to support rtl for all components i think, because everything has some text or label. Components like HighlightedText should also support rtl, for which alignment won't work.
We also want to consider if we should support rtl at the document level, to make the whole gradio app rtl.
There is more info on this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir
The CSS property should generally be avoided in favour of the html attribute.
Would we not also want to flip the orientation of our layouts for global rtl content? |
For the I also added Since
We can certainly add RTL support to |
Can't they do that with a theme? |
Disagree a bit @pngwn @hannahblair -- applying RTL to components vs. the entire Blocks are two separate issues. Applying RTL to the whole app is a lot more work since we have to modify entire layouts and is out of scope of this PR. But there are cases where only specific component (e.g. a |
As @hannahblair said, rtl handles more than just alignment. It will also lay out adjacent elements right to left, which alignment won't. This is a little more reliable, especially if we were to expand any of these components in the future to have more complex markup. With |
No a theme would apply to the entire app -- whereas this property applies on a component level |
I've mentioned before that we could pass theme properties into components to have them only apply to that component. I'd argue that text alignment is stylistic (so a theme should handle it) but rtl is semantic. In the example space you linked, what would we do about the table elements/ examples? The example does help clarify though, this is less about localisation and more about supporting multilingual apps with bits of rtl text. |
Yes exactly! We could support full RTL too, but that's for a future PR :)
The examples actually look great -- since the only thing that needs to be rendered RTL is the text in the "text" column, which is already the case |
Ok so maybe just to summarize the changes that are needed on this PR (as opposed to things we could include in a future PR):
Is that correct? |
+1 thank you for that demo example, that helps me better understand the potential usage of this :) We could apply |
@hannahblair The only issue with applying it to the parent is that it would |
Ok great, thanks @pngwn @hannahblair for the feedback! I'll make the changes requested |
All righty, backend, frontend, and stories have been updated to reflect the new parameters. I also updated the test code snippet at the top of the PR if I could get another pass! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for fixing this @abidlabs!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
Thanks folks! |
Adds support for right-to-left languages, such as Arabic or Hebrew, to
gr.Textbox
,gr.Markdown
,gr.Chatbot
I realized halfway through that this is a bit tricky, because there are two different aspects of an RTL language:
The way I've implemented this is as follows:
Textbox
component now takes a boolean parameterrtl
which sets direction to RTL and right-aligns the texttext_align
parameter that only aligns the textMarkdown
andChatbot
also take thertl
parameter. Since they don't accept text, they don't have a separatetext_align
parameter.Closes: #4325
Test code: