-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Feature: RTL #2803
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
Feature: RTL #2803
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2803 +/- ##
=======================================
Coverage 96.16% 96.17%
=======================================
Files 37 37
Lines 1227 1230 +3
Branches 383 387 +4
=======================================
+ Hits 1180 1183 +3
Misses 47 47
|
@@ -583,7 +590,7 @@ function DataGrid<R, SR, K extends Key>( | |||
function handleScroll(event: React.UIEvent<HTMLDivElement>) { | |||
const { scrollTop, scrollLeft } = event.currentTarget; | |||
setScrollTop(scrollTop); | |||
setScrollLeft(scrollLeft); | |||
setScrollLeft(abs(scrollLeft)); |
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.
It is negative in RTL
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.
Let's list RTL support in the README.
Do we have any links to open browser issues? Might be good to list them in the RTL demo page.
src/DataGrid.tsx
Outdated
@@ -368,6 +371,10 @@ function DataGrid<R, SR, K extends Key>( | |||
* effects | |||
*/ | |||
useLayoutEffect(() => { | |||
if (isRtlRef.current === undefined) { | |||
isRtlRef.current = isRtlDirection(gridRef.current!); |
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.
While this is executed on each render, it assumes that changes to the direction will trigger a re-render of RDG, which might not necessarily be true (memoized parent components, just css change, ...), so I'm not sure it's super safe.
We could have an optional direction
prop, and fall back to useLayoutEffect
if it's not specified.
I wonder if the ResizeObserver is triggered when the direction changes 🤔
src/utils/index.ts
Outdated
@@ -53,3 +53,7 @@ export function getCellClassname<R, SR>( | |||
...extraClasses | |||
); | |||
} | |||
|
|||
export function isRtlDirection(element: Element) { | |||
return getComputedStyle(element).direction === 'rtl'; |
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.
https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
The returned
style
is a liveCSSStyleDeclaration
object, which updates automatically when the element's styles are changed.
Wonder if it's worth only getting that object once.
Could use a WeakMap
for the cache.
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
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.
Let's document the direction
prop in the readme.
some new test for keyboard nav would be good too
test/column/direction.test.ts
Outdated
expect(getGrid()).toHaveAttribute('dir', 'rtl'); | ||
}); | ||
|
||
test('should not change the left and right arrow behavior for right to left languages', () => { |
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.
Could be moved to test/keyboardNavigation.test.tsx
IMO.
Co-authored-by: Nicolas Stepien <[email protected]>
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.
## [5.1.0](v5.0.4...5.1.0) (2024-01-10) ### Features * Add DataGridComponentsProvider component and DataGrid.components prop ([adazzle#2754](https://github.com/superform-xyz/react-data-grid/issues/2754)) ([f864291](f864291)) * Add support for flex column width ([adazzle#2839](https://github.com/superform-xyz/react-data-grid/issues/2839)) ([4a136ad](4a136ad)) * expose scroll event ([adazzle#2011](https://github.com/superform-xyz/react-data-grid/issues/2011)) ([7614c8e](7614c8e)) * RTL ([adazzle#2803](https://github.com/superform-xyz/react-data-grid/issues/2803)) ([c0e4a63](c0e4a63)) * semantic release installed and configured ([e71bfe6](e71bfe6)) ### Bug Fixes * drag jumps to the right due to the failed merge ([adazzle#1564](https://github.com/superform-xyz/react-data-grid/issues/1564)) ([7033a1b](7033a1b)) * isSelectedCellEditable row getter idx ([adazzle#1743](https://github.com/superform-xyz/react-data-grid/issues/1743)) ([018f137](018f137)) * package-lock.json added to version control ([df39113](df39113)) ### Reverts * Revert "Dependabot: set versioning-strategy to increase (adazzle#2479)" (adazzle#2511) ([0bedc81](0bedc81))
## [5.1.0](v5.0.4...5.1.0) (2024-01-10) ### Features * Add DataGridComponentsProvider component and DataGrid.components prop ([adazzle#2754](https://github.com/superform-xyz/react-data-grid/issues/2754)) ([f864291](f864291)) * Add support for flex column width ([adazzle#2839](https://github.com/superform-xyz/react-data-grid/issues/2839)) ([4a136ad](4a136ad)) * expose scroll event ([adazzle#2011](https://github.com/superform-xyz/react-data-grid/issues/2011)) ([7614c8e](7614c8e)) * RTL ([adazzle#2803](https://github.com/superform-xyz/react-data-grid/issues/2803)) ([c0e4a63](c0e4a63)) * semantic release installed and configured ([e71bfe6](e71bfe6)) ### Bug Fixes * drag jumps to the right due to the failed merge ([adazzle#1564](https://github.com/superform-xyz/react-data-grid/issues/1564)) ([7033a1b](7033a1b)) * isSelectedCellEditable row getter idx ([adazzle#1743](https://github.com/superform-xyz/react-data-grid/issues/1743)) ([018f137](018f137)) * package-lock.json added to version control ([df39113](df39113)) ### Reverts * Revert "Dependabot: set versioning-strategy to increase (adazzle#2479)" (adazzle#2511) ([0bedc81](0bedc81))
Fixes #1742
direction
propArrowLeft/ArrowRight
keys for RTL:dir
pseudo-class to tweak styles like box shadowsIssues:
:dir
pseudo-class but this only breaks transforms and other minor stylesfloat: inline-end
This PR only adds support for RTL and not for writing modes
Example of RTL
https://www.ag-grid.com/javascript-data-grid/rtl/
https://www.telerik.com/kendo-react-ui/components/grid/globalization/#toc-right-to-left-support