-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
jquery-ui:Base text direction support #1715
base: main
Are you sure you want to change the base?
Conversation
By analyzing the blame information on this pull request, we identified @arschmitz, @scottgonzalez and @jzaefferer to be potential reviewers |
No problem. Will be waiting for your feedback / comments. One clarification with your kind permission: #1682 is about fixing issues with GUI mirroring (relevant for several widgets). GUI mirroring is strongly associated with translation of UI to Arabic / Hebrew. At the same time, GUI mirroring is mostly concerned with graphical layout of screen and widget. As opposed to that, this specific PR is concerned with text only (which can appear as part of widget). Thus this PR is completely orthogonal to GUI direction and #1682 . Just FYI. My team and our colleagues from Egypt Bidi center (who authored #1682) work together to address variety of Bidi requirements in open source tools / libraries. |
I have not reviewed this at all yet simply read the discription. Just one minor thing i noticed from that is any time we have an "auto" option like this that determines the value used based on DOM etc, we always use the special value |
@scottgonzalez may I kindly inquire which release are we waiting for to start the review ? I believe 3.2 was out in March 2017. |
Let's focus on a single widget to have our discussions. I'll pick button since it's the first widget in the |
@scottgonzalez button is not the best example to illustrate the benefit of textDir parameter. This is mostly since button has horizontally symmetrical graphics (just a rectangular area without any shade) and thus it looks (from graphical perspective) exactly the same with both LTR and RTL directions. However even for the button there is a minor benefit. Please observe that textDir is meant to affect text only. Currently if you specify dir="ltr" or dir="rtl" for button you don't cover auto direction (aka contextual or first stong) for text label displayed as part of the button. You can specify dir="auto" for button but this won't work at least not on IE. Thus having textDir even in the case of button has some benefit. In general textDir has striking benefit for widgets which are horizontally asymmetrical. For example, combo box, list box (with scroll bar), check box, tree, grid etc. When you want to flip horizontally such widgets you usually specify dir="ltr" or dir="rtl". However, this by itself does not allow you to enforce text direction for text displayed in such widgets independently from GUI direction. For example if you specify dir="rtl" for combo box, all text inside such combo box will be displayed with RTL direction. However if you wish this text to be displayed with LTR direction you have no such option. Having textDir parameter allows you to control text direction of text inside a widget independently from direction of widget graphics. For the sake of example, please observe the behavior of native controls on iOS / Android platforms. Text in such controls is displayed by default with textDir = "auto" regardless of direction of control's graphics (dir ="ltr" or dir ="rtl"). By the way majority of desktop technologies (including native mobile libraries) allow to control direction of text independently from widget (or GUI) direction. For example:
|
Thanks for the explanation on the two different direction settings. Now that I have a better understanding of the specific goal trying to be accomplished, I will take another look at the changes. |
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.
Initial round of review.
demos/widget/textDir.html
Outdated
@@ -0,0 +1,283 @@ | |||
<!doctype html> |
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 demo will need to be removed since it's not actually a demo of the widget factory.
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.
Done.
@@ -19,6 +19,7 @@ common.testWidget( "tooltip", { | |||
}, | |||
show: true, | |||
track: false, | |||
textDir: null, |
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.
These options are alphabetized. All files will need to be updated for the correct order.
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.
Done.
ui/widget.js
Outdated
@@ -280,6 +280,8 @@ $.Widget.prototype = { | |||
classes: {}, | |||
disabled: false, | |||
|
|||
// textDir: null, |
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.
Removed commented out code.
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.
Done.
|
||
_getTextDir: function( text ) { | ||
if ( this.options.textDir === "auto" ) { | ||
var matcher = /[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec( text ); |
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.
Please add a comment about which set of characters this is searching for.
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.
Done.
} | ||
return this.options.textDir; | ||
}, | ||
_applyTextDir: function( param ) { |
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.
Blank line between methods.
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.
Done.
ui/widgets/autocomplete.js
Outdated
if ( this.options.textDir === "auto" ) { | ||
var that = this; | ||
this.element.bind( "keyup", function() { | ||
var fld = $( this ); |
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.
s/fld/element/
But that's not needed once you switch to ._on()
anyway.
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.
Indeed, changed
ui/widgets/button.js
Outdated
@@ -88,6 +89,10 @@ $.widget( "ui.button", { | |||
|
|||
this.hasTitle = !!this.element.attr( "title" ); | |||
|
|||
if ( this.options.textDir ) { | |||
this.options.label = this._applyTextDir( this.options.label ); |
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.
Doesn't this break HTML inside the button?
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.
As a matter of fact inserted UCC constitutes just text node in HTML markup and doesn't break it, while having desirable impact.
However I made changes accounting to possibility of HTML content of button widget and now the element 'direction' style gets changed instead of insertion of directional UCC.
ui/widgets/button.js
Outdated
@@ -242,6 +248,10 @@ $.widget( "ui.button", { | |||
this._updateTooltip(); | |||
} | |||
|
|||
if ( this.options.textDir && ( key === "label" || key === "textDir" ) ) { |
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.
What about handling when textDir
changes? This seems like a place where we probably need to leverage _setOptions()
instead of _setOption()
.
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.
Moved code to '_setOptions'
ui/widgets/controlgroup.js
Outdated
var dir = that.options.textDir ? | ||
"dir='" + that._getTextDir( element.text() ) + "' " : ""; | ||
|
||
element.contents().wrapAll |
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.
Don't break between method names and their invoking parens.
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.
Fixed
@@ -265,6 +266,9 @@ $.widget( "ui.tooltip", { | |||
tooltipData = this._find( target ); | |||
if ( tooltipData ) { | |||
tooltipData.tooltip.find( ".ui-tooltip-content" ).html( content ); | |||
if ( this.options.textDir ) { | |||
this._applyTextDir( tooltipData.tooltip.find( ".ui-tooltip-content" ) ); |
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.
Doesn't this break HTML inside the tooltip?
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.
By no means. In this case the tooltip.find returns JQuery object and '_applyTextDir' sets its 'direction' style
@ashensis You can just push updates to this branch and keep the PR open. |
@scottgonzalez Can you please reopen this PR ? |
|
1 similar comment
|
@scottgonzalez All comments in initial round of review had been addressed, please have a look |
@scottgonzalez Are you ok with @ashensis changes ? Did he address all your comments ? Is anything else needed to allow his code to be merged ? |
@arschmitz and @jzaefferer who is in charge to review this PR . @scottgonzales is not answering a long time |
As per discussion in https://bugs.jqueryui.com/ticket/14477, current code submit contains Base text direction support for UI widgets.
New option is introduced for relevant widgets 'textDir' with values:
'ltr' - Left-to-right text direction
'rtl' - Right-to-left text direction
'auto' - Contextual text direction that gets resolved to either 'ltr' or 'rtl' according to first strong character ('rtl' if it is Arabic/Hebrew character, 'ltr' otherwise).
Text direction option shouldn't affect the mirroring aspects of widgets having assimmetric GUI, it only impacts the text direction of contained text.
The corresponding demo textDir.html illustrates the issue for all relevant widgets.
When current approach will be approved (or modified according reviewer remaarks) documentation and unitests will be provided.