mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
fix(item): add support for rendering buttons inside of an item
TODO document
This commit is contained in:
2
packages/core/src/components.d.ts
vendored
2
packages/core/src/components.d.ts
vendored
@ -1338,6 +1338,8 @@ declare global {
|
|||||||
color?: string;
|
color?: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
mode?: 'ios' | 'md';
|
mode?: 'ios' | 'md';
|
||||||
|
onclick?: (this: HTMLElement, ev: MouseEvent) => any;
|
||||||
|
tappable?: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,18 @@ export class Item {
|
|||||||
*/
|
*/
|
||||||
@Prop() href: string;
|
@Prop() href: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {any} Callback function.
|
||||||
|
* If this property is set, a button tag will be rendered.
|
||||||
|
*/
|
||||||
|
@Prop() onclick: (this: HTMLElement, ev: MouseEvent) => any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {boolean} Whether or not this item should be tappable.
|
||||||
|
* If true, a button tag will be rendered. Default `true`.
|
||||||
|
*/
|
||||||
|
@Prop() tappable = false;
|
||||||
|
|
||||||
@Listen('ionStyle')
|
@Listen('ionStyle')
|
||||||
itemStyle(ev: UIEvent) {
|
itemStyle(ev: UIEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
@ -87,8 +99,12 @@ export class Item {
|
|||||||
|
|
||||||
this.hasStyleChange = false;
|
this.hasStyleChange = false;
|
||||||
|
|
||||||
// TODO add support for button items
|
const clickable = this.href || this.onclick || this.tappable;
|
||||||
const TagType = this.href ? 'a' : 'div';
|
|
||||||
|
let TagType = 'div';
|
||||||
|
if (clickable) {
|
||||||
|
TagType = this.href ? 'a' : 'button';
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TagType class={themedClasses}>
|
<TagType class={themedClasses}>
|
||||||
@ -99,7 +115,7 @@ export class Item {
|
|||||||
</div>
|
</div>
|
||||||
<slot name='end'></slot>
|
<slot name='end'></slot>
|
||||||
</div>
|
</div>
|
||||||
{ this.href && this.mode === 'md' && <ion-ripple-effect useTapClick={true} /> }
|
{ clickable && this.mode === 'md' && <ion-ripple-effect useTapClick={true} /> }
|
||||||
</TagType>
|
</TagType>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,16 @@ string
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### onclick
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### tappable
|
||||||
|
|
||||||
|
boolean
|
||||||
|
|
||||||
|
|
||||||
## Attributes
|
## Attributes
|
||||||
|
|
||||||
#### color
|
#### color
|
||||||
@ -39,6 +49,16 @@ string
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### onclick
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### tappable
|
||||||
|
|
||||||
|
boolean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
@ -28,16 +28,20 @@
|
|||||||
a[ion-item] secondary
|
a[ion-item] secondary
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item onclick="testClick(event)">
|
<ion-item tappable id="attachClick">
|
||||||
button[ion-item]
|
button[ion-item] tappable click listener
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item class="activated" onclick="testClick(event)">
|
<ion-item ONCLICK="testClick(event)">
|
||||||
button[ion-item].activated
|
button[ion-item] ONCLICK
|
||||||
|
</ion-item>
|
||||||
|
|
||||||
|
<ion-item class="activated" onClick="testClick(event)">
|
||||||
|
button[ion-item].activated onClick
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item color="danger" onclick="testClick(event)">
|
<ion-item color="danger" onclick="testClick(event)">
|
||||||
button[ion-item] danger
|
button[ion-item] danger onclick
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item onclick="testClickOutsize(event)">
|
<ion-item onclick="testClickOutsize(event)">
|
||||||
@ -134,6 +138,12 @@
|
|||||||
</ion-app>
|
</ion-app>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const attach = document.getElementById('attachClick');
|
||||||
|
|
||||||
|
attach.addEventListener('click', (ev) => {
|
||||||
|
console.log('clicked me!', ev);
|
||||||
|
});
|
||||||
|
|
||||||
function testClick(ev) {
|
function testClick(ev) {
|
||||||
console.log('CLICK!', ev.target.tagName, ev.target.textContent.trim());
|
console.log('CLICK!', ev.target.tagName, ev.target.textContent.trim());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user