mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
feat(back-button): add 'backButtonDefaultHref' property to Ionic Config (#20491)
closes #19305 Co-authored-by: Brandy Carney <brandy@ionic.io>
This commit is contained in:
@ -31,7 +31,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
/**
|
||||
* The url to navigate back to by default when there is no history.
|
||||
*/
|
||||
@Prop() defaultHref?: string;
|
||||
@Prop({ mutable: true }) defaultHref?: string;
|
||||
|
||||
/**
|
||||
* If `true`, the user cannot interact with the button.
|
||||
@ -53,6 +53,12 @@ export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
*/
|
||||
@Prop() type: 'submit' | 'reset' | 'button' = 'button';
|
||||
|
||||
componentWillLoad() {
|
||||
if (this.defaultHref === undefined) {
|
||||
this.defaultHref = config.get('backButtonDefaultHref');
|
||||
}
|
||||
}
|
||||
|
||||
get backButtonIcon() {
|
||||
const icon = this.icon;
|
||||
if (icon != null) {
|
||||
|
@ -70,4 +70,37 @@ describe('back button', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('backButtonDefaultHref', () => {
|
||||
|
||||
it('set custom defaultHref in the config', async () => {
|
||||
config.reset({
|
||||
backButtonDefaultHref: 'custom-default-href-config'
|
||||
});
|
||||
const bb = await newBackButton();
|
||||
expect(bb.defaultHref).toBe('custom-default-href-config');
|
||||
});
|
||||
|
||||
it('set custom defaultHref on the instance', async () => {
|
||||
const bb = await newBackButton();
|
||||
bb.defaultHref = 'custom-default-href';
|
||||
expect(bb.defaultHref).toBe('custom-default-href');
|
||||
});
|
||||
|
||||
it('set custom defaultHref on the instance, override config', async () => {
|
||||
const bb = await newBackButton();
|
||||
bb.defaultHref = 'custom-default-href';
|
||||
|
||||
config.reset({
|
||||
backButtonDefaultHref: 'custom-default-href-config'
|
||||
});
|
||||
|
||||
expect(bb.defaultHref).toBe('custom-default-href');
|
||||
|
||||
const bb2 = await newBackButton();
|
||||
bb2.defaultHref = 'custom-default-href-second';
|
||||
expect(bb2.defaultHref).toBe('custom-default-href-second');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user