Skip to content

Commit

Permalink
Tabs: Update scrollable after change the orientation option in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
marker-dao authored Sep 25, 2023
1 parent c8a97db commit b9a53b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/devextreme/js/ui/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const Tabs = CollectionWidget.inherit({
const maxLeftOffset = getScrollLeftMax($(this.getScrollable().container()).get(0));
scrollable.scrollTo({ left: maxLeftOffset });
}
this._updateNavButtonsVisibility();
this._updateNavButtonsState();

this._scrollToItem(this.option('selectedItem'));
}
Expand Down Expand Up @@ -397,16 +397,12 @@ const Tabs = CollectionWidget.inherit({
return scrollableDirection;
},

_updateScrollableDirection() {
const scrollable = this.getScrollable();

if(scrollable) {
const scrollableDirection = this._getScrollableDirection();

scrollable.option('direction', scrollableDirection);
} else {
this._renderScrolling();
_updateScrollable() {
if(this.getScrollable()) {
this._cleanScrolling();
}

this._renderScrolling();
},

_renderScrollable() {
Expand All @@ -419,7 +415,7 @@ const Tabs = CollectionWidget.inherit({
useNative: false,
scrollByContent: this.option('scrollByContent'),
onScroll: () => {
this._updateNavButtonsVisibility();
this._updateNavButtonsState();
},
});

Expand Down Expand Up @@ -452,7 +448,7 @@ const Tabs = CollectionWidget.inherit({
this.$element().append($rightButton);
},

_updateNavButtonsVisibility() {
_updateNavButtonsState() {
const isVertical = this._isVertical();
const scrollable = this.getScrollable();

Expand Down Expand Up @@ -647,7 +643,7 @@ const Tabs = CollectionWidget.inherit({
case 'orientation': {
this._toggleOrientationClass(args.value);
if(!this._isServerSide()) {
this._updateScrollableDirection();
this._updateScrollable();
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,23 @@ QUnit.module('Horizontal scrolling', () => {
assert.ok($scrollable.find('.' + TABS_ITEM_CLASS).length, 'items wrapped into scrollable');
});

QUnit.test('tabs should not be wrapped into scrollable after orientation runtime changing if component width more than total tabs width', function(assert) {
const $element = $('#scrollableTabs').dxTabs({
items: [{ text: 'item 1' }, { text: 'item 1' }],
scrollingEnabled: true,
orientation: 'vertical',
width: 500,
height: 50,
});
const instance = $element.dxTabs('instance');

assert.strictEqual($element.children(`.${SCROLLABLE_CLASS}`).length, 1, 'scroll is created');

instance.option({ orientation: 'horizontal' });

assert.strictEqual($element.children(`.${SCROLLABLE_CLASS}`).length, 0, 'scroll was removed');
});

QUnit.test('tabs should be wrapped into scrollable for some disabled items', function(assert) {
const $element = $('#scrollableTabs').dxTabs({
items: [{ text: 'item 1' }, { text: 'item 2', disabled: true }, { text: 'item 3', disabled: true }, { text: 'item 4', disabled: true }],
Expand Down

0 comments on commit b9a53b7

Please sign in to comment.