mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
refactor(tab-button): use <a href> instead of <button>
This commit is contained in:
1
packages/core/src/components.d.ts
vendored
1
packages/core/src/components.d.ts
vendored
@ -3194,6 +3194,7 @@ declare global {
|
|||||||
btnId?: string;
|
btnId?: string;
|
||||||
component?: any;
|
component?: any;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
href?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
|
@ -24,6 +24,10 @@ ion-tab-button {
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion-tab-button a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.tab-cover {
|
.tab-cover {
|
||||||
@include margin(0);
|
@include margin(0);
|
||||||
@include padding(0);
|
@include padding(0);
|
||||||
|
@ -33,8 +33,11 @@ export class TabButton {
|
|||||||
|
|
||||||
@Listen('click')
|
@Listen('click')
|
||||||
protected onClick(ev: UIEvent) {
|
protected onClick(ev: UIEvent) {
|
||||||
|
if (!this.tab.disabled) {
|
||||||
this.ionTabbarClick.emit(this.tab);
|
this.ionTabbarClick.emit(this.tab);
|
||||||
|
}
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private onKeyUp() {
|
private onKeyUp() {
|
||||||
@ -73,18 +76,19 @@ export class TabButton {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const tab = this.tab;
|
const tab = this.tab;
|
||||||
|
const href = tab.href || '#';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
<button
|
<a
|
||||||
type='button'
|
href={href}
|
||||||
class='tab-cover'
|
class='tab-cover'
|
||||||
onKeyUp={this.onKeyUp.bind(this)}
|
onKeyUp={this.onKeyUp.bind(this)}
|
||||||
onBlur={this.onBlur.bind(this)}
|
onBlur={this.onBlur.bind(this)}>
|
||||||
disabled={tab.disabled}>
|
|
||||||
{ tab.icon && <ion-icon class='tab-button-icon' name={tab.icon}></ion-icon> }
|
{ tab.icon && <ion-icon class='tab-button-icon' name={tab.icon}></ion-icon> }
|
||||||
{ tab.title && <span class='tab-button-text'>{tab.title}</span> }
|
{ tab.title && <span class='tab-button-text'>{tab.title}</span> }
|
||||||
{ tab.badge && <ion-badge class='tab-badge' color={tab.badgeStyle}>{tab.badge}</ion-badge> }
|
{ tab.badge && <ion-badge class='tab-badge' color={tab.badgeStyle}>{tab.badge}</ion-badge> }
|
||||||
{ this.mode === 'md' && <ion-ripple-effect/> }
|
{ this.mode === 'md' && <ion-ripple-effect/> }
|
||||||
</button>
|
</a>
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,13 @@ boolean
|
|||||||
If true, the user cannot interact with the tab. Defaults to `false`.
|
If true, the user cannot interact with the tab. Defaults to `false`.
|
||||||
|
|
||||||
|
|
||||||
|
#### href
|
||||||
|
|
||||||
|
string
|
||||||
|
|
||||||
|
The URL which will be used as the `href` within this tab's `<ion-tab-button>` anchor.
|
||||||
|
|
||||||
|
|
||||||
#### icon
|
#### icon
|
||||||
|
|
||||||
string
|
string
|
||||||
@ -170,6 +177,13 @@ boolean
|
|||||||
If true, the user cannot interact with the tab. Defaults to `false`.
|
If true, the user cannot interact with the tab. Defaults to `false`.
|
||||||
|
|
||||||
|
|
||||||
|
#### href
|
||||||
|
|
||||||
|
string
|
||||||
|
|
||||||
|
The URL which will be used as the `href` within this tab's `<ion-tab-button>` anchor.
|
||||||
|
|
||||||
|
|
||||||
#### icon
|
#### icon
|
||||||
|
|
||||||
string
|
string
|
||||||
|
@ -22,6 +22,11 @@ export class Tab {
|
|||||||
*/
|
*/
|
||||||
@Prop() title: string;
|
@Prop() title: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL which will be used as the `href` within this tab's `<ion-tab-button>` anchor.
|
||||||
|
*/
|
||||||
|
@Prop() href: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The icon for the tab.
|
* The icon for the tab.
|
||||||
*/
|
*/
|
||||||
@ -120,9 +125,6 @@ export class Tab {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
|
||||||
return <slot/>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachViewToDom(container: HTMLElement, cmp: string): Promise<any> {
|
function attachViewToDom(container: HTMLElement, cmp: string): Promise<any> {
|
||||||
|
Reference in New Issue
Block a user