Closed GianBe closed 8 years ago
A little update:
I'm inclined to belive that the way the selection of the text behave in the component is actually right
The current available version of fbjs does not have bidi support.
The files containing the bidi algorithm are available in the 0.8.0-alpha1 version (the one used in draftjs)
As of this release the component doesn't support rtl languages in the token navigation. RTL languages are the ones that write right to left while LTR write from left to right.
For example: If your language is arabic you will have the following situation inside an input with tokens:
[token]``[#token]``[token]
Now if you press the right arrow on the keybord the result will be:[#token]``[token]``[token]
While the expected result is:[token]``[token]``[#token]
This is a problem caused by the definition of the forward and backward direction in the code that in a rtl language are inverted.
I was trying to implement a solution to the problem, that is not really a proper solution:
The problem of the navigation inside the tokens depends on this code inside of
key-utils.js
:that needs to differentiate from rtl and ltr. My solution will operate directly in the browser with the use of the dir property inside of the HTML input.
dir
can force the displayed type of language to rtl or ltr will accept:rtl
: for right to leftltr
: for left to rightauto
: automatically managedA good reference for the use of
dir
in HTML is hereThe
dir
property with an helper function will give the right method of navigation.Now some actual code for this solution:
First of all we need 2 new states inside the
FacetedTokenInput
class:dir
Inside the actual
render
method in theFacetedTokenInput
class you will need to add:as a property of the
div
element.Now you will need to modify the
onChange
function ofFacetedTokenInput
:So if it isn't the first input we keep the current
textDirection
, if it is we call the helper functionisRTL()
that will get the current input and help detect the right language style.Finally the core of this solution,
isRTL()
is:Thanks to the help of the internet I basically found this type of function and is similar to the one that Google uses to change the position of the microphone inside its input.
ltrChars
andrtlChars
: a collection of characters that can determinate the right stylertlDirCheck
: is a regular expression that checks for the presence of ltr charactersThe function returns a boolean that represent the result of the application of the regular expression to the passed string (false if is ltr, true if is rtl).
To complete the changes the new
isForward
andisBackward
functions are:A new element is passed to the function
RTL
that represent thetextDirection
state insideFacetedTokenInput
.With all those changes the result is the right navigation inside of the tokens. The text itself is a little different, at the moment it doesn't work, probably some of the problems will disappear in a real rtl language enviroment.
Probably some changes to the
onLeftRight
function are needed.