Skip to content

Commit 335672d

Browse files
authored
refactor(modal): allow dragging when expandToScroll is false (#30235)
1 parent 57b784a commit 335672d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

core/src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ export namespace Components {
17361736
*/
17371737
"enterAnimation"?: AnimationBuilder;
17381738
/**
1739-
* Controls whether scrolling or dragging within the sheet modal expands it to a larger breakpoint. This only takes effect when `breakpoints` and `initialBreakpoint` are set. If `true`, scrolling or dragging anywhere in the modal will first expand it to the next breakpoint. Once fully expanded, scrolling will affect the content. If `false`, scrolling will always affect the content, and the modal will only expand when dragging the header or handle.
1739+
* Controls whether scrolling or dragging within the sheet modal expands it to a larger breakpoint. This only takes effect when `breakpoints` and `initialBreakpoint` are set. If `true`, scrolling or dragging anywhere in the modal will first expand it to the next breakpoint. Once fully expanded, scrolling will affect the content. If `false`, scrolling will always affect the content. The modal will only expand when dragging the header or handle. The modal will close when dragging the header or handle. It can also be closed when dragging the content, but only if the content is scrolled to the top.
17401740
*/
17411741
"expandToScroll": boolean;
17421742
/**
@@ -6553,7 +6553,7 @@ declare namespace LocalJSX {
65536553
*/
65546554
"enterAnimation"?: AnimationBuilder;
65556555
/**
6556-
* Controls whether scrolling or dragging within the sheet modal expands it to a larger breakpoint. This only takes effect when `breakpoints` and `initialBreakpoint` are set. If `true`, scrolling or dragging anywhere in the modal will first expand it to the next breakpoint. Once fully expanded, scrolling will affect the content. If `false`, scrolling will always affect the content, and the modal will only expand when dragging the header or handle.
6556+
* Controls whether scrolling or dragging within the sheet modal expands it to a larger breakpoint. This only takes effect when `breakpoints` and `initialBreakpoint` are set. If `true`, scrolling or dragging anywhere in the modal will first expand it to the next breakpoint. Once fully expanded, scrolling will affect the content. If `false`, scrolling will always affect the content. The modal will only expand when dragging the header or handle. The modal will close when dragging the header or handle. It can also be closed when dragging the content, but only if the content is scrolled to the top.
65576557
*/
65586558
"expandToScroll"?: boolean;
65596559
/**

core/src/components/modal/gestures/sheet.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ export const createSheetGesture = (
192192
currentBreakpoint = getCurrentBreakpoint();
193193

194194
/**
195-
* If we have expandToScroll disabled, we should not allow the swipe gesture to start
196-
* if the content is being swiped.
195+
* If `expandToScroll` is disabled, we should not allow the swipe gesture
196+
* to start if the content is not scrolled to the top.
197197
*/
198198
if (!expandToScroll && contentEl) {
199-
return false;
199+
const scrollEl = isIonContent(contentEl) ? getElementRoot(contentEl).querySelector('.inner-scroll') : contentEl;
200+
return scrollEl!.scrollTop === 0;
200201
}
201202

202203
if (currentBreakpoint === 1 && contentEl) {
@@ -262,6 +263,14 @@ export const createSheetGesture = (
262263
};
263264

264265
const onMove = (detail: GestureDetail) => {
266+
/**
267+
* If `expandToScroll` is disabled, we should not allow the swipe gesture
268+
* to continue if the gesture is not pulling down.
269+
*/
270+
if (!expandToScroll && detail.deltaY <= 0) {
271+
return;
272+
}
273+
265274
/**
266275
* If we are pulling down, then it is possible we are pulling on the content.
267276
* We do not want scrolling to happen at the same time as the gesture.

core/src/components/modal/modal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ export class Modal implements ComponentInterface, OverlayInterface {
136136
* and `initialBreakpoint` are set.
137137
*
138138
* If `true`, scrolling or dragging anywhere in the modal will first expand
139-
* it to the next breakpoint. Once fully expanded, scrolling will affect the content.
140-
* If `false`, scrolling will always affect the content, and the modal will only expand
141-
* when dragging the header or handle.
139+
* it to the next breakpoint. Once fully expanded, scrolling will affect the
140+
* content.
141+
* If `false`, scrolling will always affect the content. The modal will
142+
* only expand when dragging the header or handle. The modal will close when
143+
* dragging the header or handle. It can also be closed when dragging the
144+
* content, but only if the content is scrolled to the top.
142145
*/
143146
@Prop() expandToScroll = true;
144147

0 commit comments

Comments
 (0)