Skip to content

Commit ceb41f3

Browse files
fix(angular): popover arrow navigation with disabled items (#29662)
Issue number: resolves #29640 --------- ## What is the current behavior? (Angular) If a list inside of a popover contains a disabled item and is included in the following way: ```html <ion-list> <ion-item [button]="true">Option 1</ion-item> <ion-item [button]="true" [disabled]="true">Option 2</ion-item> <ion-item [button]="true">Option 3</ion-item> </ion-list> ``` when you try to navigate using the arrow down keys, it will stop at the disabled item instead of continuing over it. Note that changing the item to the following will work: ```html <ion-item [button]="true" disabled="true">Option 2</ion-item> ``` ## What is the new behavior? Reflect the `disabled` property in the item so that when items are queried in the popover, the arrow down key skips over the disabled item. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information This can be tested in the Angular test app by following the documentation here: https://github.com/ionic-team/ionic-framework/blob/main/docs/angular/testing.md Removing my fix in `core`, then running `npm run build` and re-syncing the test app should reproduce the problem.
1 parent 3d6e2c4 commit ceb41f3

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

core/api.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ ion-item,prop,button,boolean,false,false,false
783783
ion-item,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
784784
ion-item,prop,detail,boolean | undefined,undefined,false,false
785785
ion-item,prop,detailIcon,string,chevronForward,false,false
786-
ion-item,prop,disabled,boolean,false,false,false
786+
ion-item,prop,disabled,boolean,false,false,true
787787
ion-item,prop,download,string | undefined,undefined,false,false
788788
ion-item,prop,href,string | undefined,undefined,false,false
789789
ion-item,prop,lines,"full" | "inset" | "none" | undefined,undefined,false,false

core/src/components/item/item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
6464
/**
6565
* If `true`, the user cannot interact with the item.
6666
*/
67-
@Prop() disabled = false;
67+
@Prop({ reflect: true }) disabled = false;
6868

6969
/**
7070
* This attribute instructs browsers to download a URL instead of navigating to

packages/angular/test/base/e2e/src/lazy/popover.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ describe('Popovers: Inline', () => {
2222
cy.get('ion-list ion-item:nth-child(3)').should('have.text', 'C');
2323
cy.get('ion-list ion-item:nth-child(4)').should('have.text', 'D');
2424
});
25+
26+
it('should have an item with a disabled attribute', () => {
27+
cy.get('ion-button').click();
28+
29+
cy.get('ion-popover').should('be.visible');
30+
31+
cy.wait(1500);
32+
33+
cy.get('ion-list ion-item:nth-child(3)').should('have.attr', 'disabled');
34+
});
2535
});

packages/angular/test/base/src/app/lazy/home-page/home-page.component.html

+5
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@
5757
Accordions Test
5858
</ion-label>
5959
</ion-item>
60+
<ion-item routerLink="/lazy/popover-inline">
61+
<ion-label>
62+
Popovers
63+
</ion-label>
64+
</ion-item>
6065
</ion-list>
6166
</ion-content>

packages/angular/test/base/src/app/lazy/popover-inline/popover-inline.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<ng-template>
55
<ion-content>
66
<ion-list>
7-
<ion-item *ngFor="let item of items">
8-
<ion-label>{{ item }}</ion-label>
7+
<ion-item *ngFor="let item of items" [button]="true" [disabled]="item.disabled">
8+
<ion-label>{{ item.text }}</ion-label>
99
</ion-item>
1010
</ion-list>
1111
</ion-content>

packages/angular/test/base/src/app/lazy/popover-inline/popover-inline.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import { IonPopover } from "@ionic/angular";
1313
})
1414
export class PopoverInlineComponent {
1515

16-
items: string[] = [];
16+
items: {text: string, disabled?: boolean}[] = [];
1717

1818
openPopover(popover: IonPopover) {
1919
popover.present();
2020

2121
setTimeout(() => {
22-
this.items = ['A', 'B', 'C', 'D'];
22+
this.items = [{text: 'A'}, {text: 'B'}, {text: 'C', disabled: true}, {text: 'D'}];
2323
}, 1000);
2424
}
2525

0 commit comments

Comments
 (0)