Skip to content

Commit

Permalink
Splitter: resizeEnd event should be fired after panes sizes update (T…
Browse files Browse the repository at this point in the history
…1240125) (#27793)
  • Loading branch information
nikkithelegendarypokemonster authored Jul 18, 2024
1 parent fae6304 commit 235f32b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 38 deletions.
10 changes: 1 addition & 9 deletions packages/devextreme/js/__internal/ui/splitter/splitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,20 +524,12 @@ class Splitter extends CollectionWidget<Properties> {
event,
handleElement: getPublicElement<HTMLElement>($resizeHandle),
};

this._getAction(RESIZE_EVENT.onResizeEnd)(eventArgs);

if (eventArgs.cancel) {
// @ts-expect-error ts-error
event.cancel = true;
return;
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
this._feedbackDeferred?.resolve();
this._toggleActiveState($resizeHandle, false);

this._updateItemSizes();
this._getAction(RESIZE_EVENT.onResizeEnd)(eventArgs);
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme/js/ui/splitter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type ResizeStartEvent<TKey = any> = Cancelable & NativeEventInfo<dxSplitt
* @type object
* @inherits Cancelable,NativeEventInfo,_ui_splitter_ResizeInfo
*/
export type ResizeEndEvent<TKey = any> = Cancelable & NativeEventInfo<dxSplitter<TKey>, KeyboardEvent | PointerEvent | MouseEvent | TouchEvent> & ResizeInfo;
export type ResizeEndEvent<TKey = any> = NativeEventInfo<dxSplitter<TKey>, KeyboardEvent | PointerEvent | MouseEvent | TouchEvent> & ResizeInfo;

/**
* @docid _ui_splitter_ItemCollapsedEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,22 @@ QUnit.module('Visibility of control elements', {
});

QUnit.module('Events', moduleConfig, () => {
QUnit.test('items sizes should be already updated when onResizeEnd is raised (T1240125)', function(assert) {
assert.expect(1);

this.reinit({
onResizeEnd: (eventArgs) => {
const newItems = eventArgs.component.option('items');
assert.strictEqual(newItems[0].size, firstPaneInitialSize + delta, 'Size of the first item should be updated');
},
dataSource: [{ text: 'Pane_1' }, { text: 'Pane_2' }]
});
const firstPaneInitialSize = this.instance.option('items')[0].size;
const delta = 90;
const pointer = pointerMock(this.getResizeHandles(false).eq(0));
pointer.start().dragStart().drag(delta, 0).dragEnd();
});

['onResizeStart', 'onResize', 'onResizeEnd'].forEach(eventHandler => {
QUnit.test(`${eventHandler} should be called when handle dragged`, function(assert) {
const resizeHandlerStub = sinon.stub();
Expand Down Expand Up @@ -2948,29 +2964,6 @@ QUnit.module('Events', moduleConfig, () => {
this.assertLayout([50, 50]);
assert.true(resizeEvent.event.cancel);
});

QUnit.test('onResizeEnd event should be cancellable', function(assert) {
let resizeEvent;
this.reinit({
width: 408,
height: 408,
dataSource: [{ size: '200px' }, { size: '200px' }],
onResizeEnd: function(e) {
resizeEvent = e;
e.cancel = true;
},
});

const pointer = pointerMock(this.getResizeHandles().eq(0));
pointer.start().dragStart().drag(100, 100).dragEnd();

const firstPaneSize = this.instance.option('items[0].size');
const secondPaneSize = this.instance.option('items[1].size');

assert.strictEqual(firstPaneSize, 200);
assert.strictEqual(secondPaneSize, 200);
assert.true(resizeEvent.event.cancel);
});
});

QUnit.module('Nested Splitters', moduleConfig, () => {
Expand Down
9 changes: 4 additions & 5 deletions packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25667,11 +25667,10 @@ declare module DevExpress.ui {
/**
* [descr:_ui_splitter_ResizeEndEvent]
*/
export type ResizeEndEvent<TKey = any> = DevExpress.events.Cancelable &
DevExpress.events.NativeEventInfo<
dxSplitter<TKey>,
KeyboardEvent | PointerEvent | MouseEvent | TouchEvent
> &
export type ResizeEndEvent<TKey = any> = DevExpress.events.NativeEventInfo<
dxSplitter<TKey>,
KeyboardEvent | PointerEvent | MouseEvent | TouchEvent
> &
ResizeInfo;
/**
* [descr:_ui_splitter_ResizeEvent]
Expand Down

0 comments on commit 235f32b

Please sign in to comment.