mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 10:01:59 +08:00
feat(segment): add swipeGesture property to allow for disabling of the swipe gesture (#22087)
resolves #22048
This commit is contained in:
@ -661,8 +661,8 @@ export class IonSearchbar {
|
|||||||
}
|
}
|
||||||
export declare interface IonSegment extends Components.IonSegment {
|
export declare interface IonSegment extends Components.IonSegment {
|
||||||
}
|
}
|
||||||
@ProxyCmp({ inputs: ["color", "disabled", "mode", "scrollable", "value"] })
|
@ProxyCmp({ inputs: ["color", "disabled", "mode", "scrollable", "swipeGesture", "value"] })
|
||||||
@Component({ selector: "ion-segment", changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-content></ng-content>", inputs: ["color", "disabled", "mode", "scrollable", "value"] })
|
@Component({ selector: "ion-segment", changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-content></ng-content>", inputs: ["color", "disabled", "mode", "scrollable", "swipeGesture", "value"] })
|
||||||
export class IonSegment {
|
export class IonSegment {
|
||||||
ionChange!: EventEmitter<CustomEvent>;
|
ionChange!: EventEmitter<CustomEvent>;
|
||||||
protected el: HTMLElement;
|
protected el: HTMLElement;
|
||||||
|
@ -1015,6 +1015,7 @@ ion-segment,prop,color,string | undefined,undefined,false,false
|
|||||||
ion-segment,prop,disabled,boolean,false,false,false
|
ion-segment,prop,disabled,boolean,false,false,false
|
||||||
ion-segment,prop,mode,"ios" | "md",undefined,false,false
|
ion-segment,prop,mode,"ios" | "md",undefined,false,false
|
||||||
ion-segment,prop,scrollable,boolean,false,false,false
|
ion-segment,prop,scrollable,boolean,false,false,false
|
||||||
|
ion-segment,prop,swipeGesture,boolean,true,false,false
|
||||||
ion-segment,prop,value,null | string | undefined,undefined,false,false
|
ion-segment,prop,value,null | string | undefined,undefined,false,false
|
||||||
ion-segment,event,ionChange,SegmentChangeEventDetail,true
|
ion-segment,event,ionChange,SegmentChangeEventDetail,true
|
||||||
ion-segment,css-prop,--background
|
ion-segment,css-prop,--background
|
||||||
|
8
core/src/components.d.ts
vendored
8
core/src/components.d.ts
vendored
@ -2064,6 +2064,10 @@ export namespace Components {
|
|||||||
* If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons.
|
* If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons.
|
||||||
*/
|
*/
|
||||||
"scrollable": boolean;
|
"scrollable": boolean;
|
||||||
|
/**
|
||||||
|
* If `true`, users will be able to swipe between segment buttons to activate them.
|
||||||
|
*/
|
||||||
|
"swipeGesture": boolean;
|
||||||
/**
|
/**
|
||||||
* the value of the segment.
|
* the value of the segment.
|
||||||
*/
|
*/
|
||||||
@ -5374,6 +5378,10 @@ declare namespace LocalJSX {
|
|||||||
* If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons.
|
* If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons.
|
||||||
*/
|
*/
|
||||||
"scrollable"?: boolean;
|
"scrollable"?: boolean;
|
||||||
|
/**
|
||||||
|
* If `true`, users will be able to swipe between segment buttons to activate them.
|
||||||
|
*/
|
||||||
|
"swipeGesture"?: boolean;
|
||||||
/**
|
/**
|
||||||
* the value of the segment.
|
* the value of the segment.
|
||||||
*/
|
*/
|
||||||
|
@ -566,13 +566,14 @@ export default defineComponent({
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Property | Attribute | Description | Type | Default |
|
| Property | Attribute | Description | Type | Default |
|
||||||
| ------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ----------- |
|
| -------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ----------- |
|
||||||
| `color` | `color` | The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics). | `string \| undefined` | `undefined` |
|
| `color` | `color` | The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics). | `string \| undefined` | `undefined` |
|
||||||
| `disabled` | `disabled` | If `true`, the user cannot interact with the segment. | `boolean` | `false` |
|
| `disabled` | `disabled` | If `true`, the user cannot interact with the segment. | `boolean` | `false` |
|
||||||
| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` |
|
| `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` |
|
||||||
| `scrollable` | `scrollable` | If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons. | `boolean` | `false` |
|
| `scrollable` | `scrollable` | If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons. | `boolean` | `false` |
|
||||||
| `value` | `value` | the value of the segment. | `null \| string \| undefined` | `undefined` |
|
| `swipeGesture` | `swipe-gesture` | If `true`, users will be able to swipe between segment buttons to activate them. | `boolean` | `true` |
|
||||||
|
| `value` | `value` | the value of the segment. | `null \| string \| undefined` | `undefined` |
|
||||||
|
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
@ -65,6 +65,16 @@ export class Segment implements ComponentInterface {
|
|||||||
*/
|
*/
|
||||||
@Prop() scrollable = false;
|
@Prop() scrollable = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If `true`, users will be able to swipe between segment buttons to activate them.
|
||||||
|
*/
|
||||||
|
@Prop() swipeGesture = true;
|
||||||
|
|
||||||
|
@Watch('swipeGesture')
|
||||||
|
swipeGestureChanged() {
|
||||||
|
this.gestureChanged();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of the segment.
|
* the value of the segment.
|
||||||
*/
|
*/
|
||||||
@ -111,8 +121,8 @@ export class Segment implements ComponentInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private gestureChanged() {
|
private gestureChanged() {
|
||||||
if (this.gesture && !this.scrollable) {
|
if (this.gesture) {
|
||||||
this.gesture.enable(!this.disabled);
|
this.gesture.enable(!this.scrollable && !this.disabled && this.swipeGesture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +147,6 @@ export class Segment implements ComponentInterface {
|
|||||||
onMove: ev => this.onMove(ev),
|
onMove: ev => this.onMove(ev),
|
||||||
onEnd: ev => this.onEnd(ev),
|
onEnd: ev => this.onEnd(ev),
|
||||||
});
|
});
|
||||||
this.gesture.enable(!this.scrollable);
|
|
||||||
this.gestureChanged();
|
this.gestureChanged();
|
||||||
|
|
||||||
if (this.disabled) {
|
if (this.disabled) {
|
||||||
@ -390,9 +399,18 @@ export class Segment implements ComponentInterface {
|
|||||||
private onClick = (ev: Event) => {
|
private onClick = (ev: Event) => {
|
||||||
const current = ev.target as HTMLIonSegmentButtonElement;
|
const current = ev.target as HTMLIonSegmentButtonElement;
|
||||||
const previous = this.checked;
|
const previous = this.checked;
|
||||||
|
|
||||||
|
// If the current element is a segment then that means
|
||||||
|
// the user tried to swipe to a segment button and
|
||||||
|
// click a segment button at the same time so we should
|
||||||
|
// not update the checked segment button
|
||||||
|
if (current.tagName === 'ION-SEGMENT') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.value = current.value;
|
this.value = current.value;
|
||||||
|
|
||||||
if (this.scrollable) {
|
if (this.scrollable || !this.swipeGesture) {
|
||||||
if (previous) {
|
if (previous) {
|
||||||
this.checkButton(previous, current);
|
this.checkButton(previous, current);
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,6 +198,9 @@
|
|||||||
<div class="ion-padding">
|
<div class="ion-padding">
|
||||||
<ion-button expand="block" color="secondary" onClick="toggleValue()">Toggle Value</ion-button>
|
<ion-button expand="block" color="secondary" onClick="toggleValue()">Toggle Value</ion-button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ion-padding-horizontal">
|
||||||
|
<ion-button expand="block" color="tertiary" onClick="toggleSwipeGesture()">Toggle Swipe Gesture</ion-button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var dynamicAttrDisable = document.getElementsByName('dynamicAttrDisable');
|
var dynamicAttrDisable = document.getElementsByName('dynamicAttrDisable');
|
||||||
@ -229,6 +232,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleSwipeGesture() {
|
||||||
|
const ionSegmentElement = document.querySelectorAll('ion-segment');
|
||||||
|
for (var i = 0; i < ionSegmentElement.length; i++) {
|
||||||
|
ionSegmentElement[i].swipeGesture = !ionSegmentElement[i].swipeGesture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function listenForEvent() {
|
async function listenForEvent() {
|
||||||
const ionSegmentElement = document.querySelector('ion-segment.event-tester');
|
const ionSegmentElement = document.querySelector('ion-segment.event-tester');
|
||||||
ionSegmentElement.addEventListener('ionChange', (event) => {
|
ionSegmentElement.addEventListener('ionChange', (event) => {
|
||||||
|
@ -574,6 +574,7 @@ export const IonSegment = /*@__PURE__*/ defineContainer<JSX.IonSegment>('ion-seg
|
|||||||
'color',
|
'color',
|
||||||
'disabled',
|
'disabled',
|
||||||
'scrollable',
|
'scrollable',
|
||||||
|
'swipeGesture',
|
||||||
'value',
|
'value',
|
||||||
'ionChange',
|
'ionChange',
|
||||||
'ionSelect',
|
'ionSelect',
|
||||||
|
Reference in New Issue
Block a user