Skip to content

Commit 67d6d31

Browse files
authored
Add rtl support (#1706)
* Initial rtl support * Fix the styles, update frozen, add rtl visual tests * Optimize frozen cells calculations * Add test for frozen columns * Import dir mixin in tree toggle * Fix FF issues with normalizedScrollLeft * Fix sorter order * Update sorting visual tests and fix tree toggle rtl material * Add missing sorting styles * Move toggle margin to not(rtl) * Bump dependencies * Move _updateScrollerMeasurements to vaadin-grid-scroll-mixin * Remove extra count styles * Update helper * Bump version
1 parent 06fdf4e commit 67d6d31

File tree

57 files changed

+339
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+339
-163
lines changed

bower.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@
6464
"iron-ajax": "PolymerElements/iron-ajax#^v2.0.0",
6565
"app-localize-behavior": "^v2.0.0",
6666
"iron-list": "^v2.0.4",
67-
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.0.0",
67+
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.1.0-alpha1",
6868
"vaadin-button": "vaadin/vaadin-button#^2.1.0",
69-
"vaadin-context-menu": "^4.3.1"
69+
"vaadin-context-menu": "vaadin/vaadin-context-menu#^4.4.0-alpha1"
7070
},
7171
"dependencies": {
7272
"polymer": "^2.0.0",
7373
"iron-resizable-behavior": "PolymerElements/iron-resizable-behavior#^v2.0.0",
7474
"iron-scroll-target-behavior": "PolymerElements/iron-scroll-target-behavior#^v2.0.0",
7575
"iron-a11y-keys-behavior": "^v2.0.0",
7676
"iron-a11y-announcer": "^v2.0.0",
77-
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.2.1",
78-
"vaadin-checkbox": "vaadin/vaadin-checkbox#^2.2.1",
79-
"vaadin-text-field": "vaadin/vaadin-text-field#^2.1.1",
80-
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.1.1",
81-
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.1.1",
82-
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.1.1"
77+
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.5.2",
78+
"vaadin-checkbox": "vaadin/vaadin-checkbox#^2.3.0-alpha1",
79+
"vaadin-text-field": "vaadin/vaadin-text-field#^2.6.0-alpha4",
80+
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.6.0",
81+
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.3.2",
82+
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.3.2"
8383
}
8484
}

src/vaadin-grid-column.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<link rel="import" href="../../polymer/polymer-element.html">
88
<link rel="import" href="../../polymer/lib/utils/flattened-nodes-observer.html">
9+
<link rel="import" href="../../vaadin-element-mixin/vaadin-dir-mixin.html">
910
<link rel="import" href="vaadin-grid-templatizer.html">
1011

1112
<script>
@@ -512,7 +513,7 @@
512513
* @memberof Vaadin
513514
* @mixes Vaadin.Grid.ColumnBaseMixin
514515
*/
515-
class GridColumnElement extends Vaadin.Grid.ColumnBaseMixin(Polymer.Element) {
516+
class GridColumnElement extends Vaadin.Grid.ColumnBaseMixin(Vaadin.DirMixin(Polymer.Element)) {
516517
static get is() {
517518
return 'vaadin-grid-column';
518519
}

src/vaadin-grid-scroll-mixin.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,22 @@
350350
cell.style.transform = '';
351351
});
352352
this._frozenCells = Array.prototype.slice.call(this.$.table.querySelectorAll('[frozen]'));
353+
this._updateScrollerMeasurements();
353354
this._translateStationaryElements();
354355
}
355356
);
356357
this._updateLastFrozen();
357358
}
358359

360+
_updateScrollerMeasurements() {
361+
if (this._frozenCells.length > 0 && this.__isRTL) {
362+
this.__scrollerMetrics = {
363+
scrollWidth: this.$.outerscroller.scrollWidth,
364+
clientWidth: this.$.outerscroller.clientWidth
365+
};
366+
}
367+
}
368+
359369
_updateLastFrozen() {
360370
if (!this._columnTree) {
361371
return;
@@ -386,9 +396,15 @@
386396
this.$.footer.style.transform = this.$.header.style.transform = this._getTranslate(0, this._scrollTop);
387397
}
388398

389-
var frozenCellTransform = this._getTranslate(this._scrollLeft, 0);
390-
for (var i = 0; i < this._frozenCells.length; i++) {
391-
this._frozenCells[i].style.transform = frozenCellTransform;
399+
if (this._frozenCells.length > 0) {
400+
const x = this.__isRTL ?
401+
this.__getNormalizedScrollLeft(this.$.table) + this.__scrollerMetrics.clientWidth -
402+
this.__scrollerMetrics.scrollWidth
403+
: this._scrollLeft;
404+
var frozenCellTransform = this._getTranslate(x, 0);
405+
for (var i = 0; i < this._frozenCells.length; i++) {
406+
this._frozenCells[i].style.transform = frozenCellTransform;
407+
}
392408
}
393409
}
394410

src/vaadin-grid-sorter.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="import" href="../../polymer/polymer.html">
88
<link rel="import" href="../../polymer/lib/elements/custom-style.html">
99
<link rel="import" href="../../vaadin-themable-mixin/vaadin-themable-mixin.html">
10+
<link rel="import" href="../../vaadin-element-mixin/vaadin-dir-mixin.html">
1011

1112
<custom-style>
1213
<style>
@@ -45,6 +46,7 @@
4546

4647
[part="indicators"]::before {
4748
font-family: 'vaadin-grid-sorter-icons';
49+
display: inline-block;
4850
}
4951

5052
:host(:not([direction])) [part="indicators"]::before {
@@ -102,7 +104,7 @@
102104
*
103105
* @memberof Vaadin
104106
*/
105-
class GridSorterElement extends Vaadin.ThemableMixin(Polymer.Element) {
107+
class GridSorterElement extends Vaadin.ThemableMixin(Vaadin.DirMixin(Polymer.Element)) {
106108
static get is() {
107109
return 'vaadin-grid-sorter';
108110
}

src/vaadin-grid-styles.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,28 @@
306306
width: 100%;
307307
will-change: transform;
308308
}
309+
310+
/* RTL specific styles */
311+
312+
:host([dir="rtl"]) [part~="reorder-ghost"] {
313+
left: auto;
314+
right: 0;
315+
}
316+
317+
:host([dir="rtl"]) [part~="resize-handle"] {
318+
left: 0;
319+
right: auto;
320+
}
321+
322+
:host([dir="rtl"]) [part~="resize-handle"]::before {
323+
transform: translateX(50%);
324+
}
325+
326+
:host([dir="rtl"]) [last-column] [part~="resize-handle"]::before,
327+
:host([dir="rtl"]) [last-frozen] [part~="resize-handle"]::before {
328+
left: 0;
329+
right: auto;
330+
}
309331
</style>
310332
`);
311333

src/vaadin-grid-tree-toggle.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<link rel="import" href="../../polymer/lib/elements/custom-style.html">
99
<link rel="import" href="../../polymer/lib/utils/debounce.html">
1010
<link rel="import" href="../../vaadin-themable-mixin/vaadin-themable-mixin.html">
11+
<link rel="import" href="../../vaadin-element-mixin/vaadin-dir-mixin.html">
1112

1213
<custom-style>
1314
<style>
@@ -129,7 +130,7 @@
129130
* @memberof Vaadin
130131
* @mixes Vaadin.ThemableMixin
131132
*/
132-
class GridTreeToggleElement extends Vaadin.ThemableMixin(Polymer.Element) {
133+
class GridTreeToggleElement extends Vaadin.ThemableMixin(Vaadin.DirMixin(Polymer.Element)) {
133134
static get is() {
134135
return 'vaadin-grid-tree-toggle';
135136
}

src/vaadin-grid.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@
420420
this.recalculateColumnWidths();
421421
}
422422

423+
attributeChangedCallback(name, oldValue, newValue) {
424+
super.attributeChangedCallback(name, oldValue, newValue);
425+
if (name === 'dir') {
426+
this.__isRTL = newValue === 'rtl';
427+
}
428+
}
429+
423430
__hasRowsWithClientHeight() {
424431
return !!Array.from(this.$.items.children).filter(row => row.clientHeight).length;
425432
}
@@ -770,6 +777,7 @@
770777
_resizeHandler() {
771778
this._updateDetailsCellHeights();
772779
this._accessIronListAPI(super._resizeHandler, true);
780+
this._updateScrollerMeasurements();
773781
this._updateHeaderFooterMetrics();
774782
}
775783

test/.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"scrollToEnd": false,
4141
"isFullOfItems": false,
4242
"isVisible": false,
43+
"isWithinParentConstraints": false,
44+
"getCustomCSSPropertyValue": false,
4345
"defaultCellWidth": false,
4446
"listenOnce": false,
4547
"MockInteractions": false,

0 commit comments

Comments
 (0)