From a02b77309aa556c1ddd2c4bb4288b4c18d298890 Mon Sep 17 00:00:00 2001 From: Shpileva Yuliya Date: Fri, 26 May 2023 18:19:32 +0400 Subject: [PATCH] Lookup: fix drop down position in chrome on android (T1165271) (#24756) Co-authored-by: Shpileva Yuliya --- js/ui/lookup.js | 19 +++++++++++++-- .../lookup.tests.js | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/js/ui/lookup.js b/js/ui/lookup.js index 15f860813399..b8351d591bd9 100644 --- a/js/ui/lookup.js +++ b/js/ui/lookup.js @@ -45,6 +45,7 @@ const GROUP_LIST_HEADER_CLASS = 'dx-list-group-header'; const MATERIAL_LOOKUP_LIST_ITEMS_COUNT = 5; const MATERIAL_LOOKUP_LIST_PADDING = 8; +const WINDOW_RATIO = 0.8; const Lookup = DropDownList.inherit({ @@ -61,6 +62,16 @@ const Lookup = DropDownList.inherit({ }, _getDefaultOptions: function() { + const getSize = (side) => { + let size; + if(devices.real().deviceType === 'phone' && window.visualViewport) { + size = window.visualViewport[side]; + } else { + size = side === 'width' ? getWidth(window) : getHeight(window); + } + return size * WINDOW_RATIO; + }; + return extend(this.callBase(), { placeholder: messageLocalization.format('Select'), @@ -129,9 +140,13 @@ const Lookup = DropDownList.inherit({ dropDownOptions: { showTitle: true, - width: function() { return getWidth(window) * 0.8; }, + width: function() { + return getSize('width'); + }, - height: function() { return getHeight(window) * 0.8; }, + height: function() { + return getSize('height'); + }, shading: true, diff --git a/testing/tests/DevExpress.ui.widgets.editors/lookup.tests.js b/testing/tests/DevExpress.ui.widgets.editors/lookup.tests.js index 5ac6c79df684..f8fe5b99feab 100644 --- a/testing/tests/DevExpress.ui.widgets.editors/lookup.tests.js +++ b/testing/tests/DevExpress.ui.widgets.editors/lookup.tests.js @@ -82,6 +82,8 @@ const SCROLL_VIEW_LOAD_PANEL_CLASS = 'dx-scrollview-loadpanel'; const FOCUSED_CLASS = 'dx-state-focused'; +const WINDOW_RATIO = 0.8; + const toSelector = function(val) { return '.' + val; }; @@ -1543,6 +1545,28 @@ QUnit.module('options', { assert.equal(autoValue, initialValue, 'initial value equal auto value'); }); + QUnit.test('popup height should have correct size on mobile devices', function(assert) { + if(devices.real().deviceType !== 'phone') { + assert.ok(true, 'not mobile device'); + return; + } + const initialVisualViewport = window.visualViewport; + + try { + window.visualViewport = { height: 510, width: 405 }; + const $lookup = $('#lookup'); + const instance = $lookup.dxLookup({}).dxLookup('instance'); + + instance.open(); + const popup = $lookup.find(`.${POPUP_CLASS}`).dxPopup('instance'); + + assert.equal(popup.option('height')(), 510 * WINDOW_RATIO); + assert.equal(popup.option('width')(), 405 * WINDOW_RATIO); + } finally { + window.visualViewport = initialVisualViewport; + } + }); + QUnit.test('searchPlaceholder', function(assert) { const instance = $('#lookup').dxLookup({ dataSource: [1, 2, 3],