Skip to content

Commit 02c9d64

Browse files
JoaoFerreira-FrontEndbrandyscarneyIonitron
authored
feat(avatar): add disabled property (#30284)
Issue number: internal --------- ## What is the current behavior? Avatar does not have a disabled state for the ionic theme. ## What is the new behavior? - Added styles for ionic theme disabled state - Added states e2e test & snapshots ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> [Preview](https://ionic-framework-git-rou-11728-ionic1.vercel.app/src/components/avatar/test/states?ionic:theme=ionic) --------- Co-authored-by: Brandy Smith <[email protected]> Co-authored-by: ionitron <[email protected]>
1 parent c5fb051 commit 02c9d64

File tree

12 files changed

+91
-7
lines changed

12 files changed

+91
-7
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ ion-app,prop,theme,"ios" | "md" | "ionic",undefined,false,false
185185
ion-app,method,setFocus,setFocus(elements: HTMLElement[]) => Promise<void>
186186

187187
ion-avatar,shadow
188+
ion-avatar,prop,disabled,boolean,false,false,false
188189
ion-avatar,prop,mode,"ios" | "md",undefined,false,false
189190
ion-avatar,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
190191
ion-avatar,prop,size,"large" | "medium" | "small" | "xlarge" | "xsmall" | "xxsmall" | undefined,undefined,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ export namespace Components {
343343
"theme"?: "ios" | "md" | "ionic";
344344
}
345345
interface IonAvatar {
346+
/**
347+
* If `true`, the user cannot interact with the avatar.
348+
*/
349+
"disabled": boolean;
346350
/**
347351
* The mode determines the platform behaviors of the component.
348352
*/
@@ -5759,6 +5763,10 @@ declare namespace LocalJSX {
57595763
"theme"?: "ios" | "md" | "ionic";
57605764
}
57615765
interface IonAvatar {
5766+
/**
5767+
* If `true`, the user cannot interact with the avatar.
5768+
*/
5769+
"disabled"?: boolean;
57625770
/**
57635771
* The mode determines the platform behaviors of the component.
57645772
*/

core/src/components/avatar/avatar.ionic.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@
171171
:host(.avatar-xxsmall) ::slotted(ion-badge.badge-vertical-bottom:empty) {
172172
transform: translate(globals.$ion-scale-100, calc(globals.$ion-scale-100));
173173
}
174+
175+
// Avatar Disabled
176+
// --------------------------------------------------
177+
:host(.avatar-disabled)::before {
178+
@include globals.disabled-state();
179+
}

core/src/components/avatar/avatar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export class Avatar implements ComponentInterface {
4040
*/
4141
@Prop() shape?: 'soft' | 'round' | 'rectangular';
4242

43+
/**
44+
* If `true`, the user cannot interact with the avatar.
45+
*/
46+
@Prop() disabled = false;
47+
4348
get hasImage() {
4449
return !!this.el.querySelector('ion-img') || !!this.el.querySelector('img');
4550
}
@@ -81,6 +86,7 @@ export class Avatar implements ComponentInterface {
8186
}
8287

8388
render() {
89+
const { hasImage, hasIcon, disabled } = this;
8490
const theme = getIonTheme(this);
8591
const size = this.getSize();
8692
const shape = this.getShape();
@@ -91,8 +97,9 @@ export class Avatar implements ComponentInterface {
9197
[theme]: true,
9298
[`avatar-${size}`]: size !== undefined,
9399
[`avatar-${shape}`]: shape !== undefined,
94-
[`avatar-image`]: this.hasImage,
95-
[`avatar-icon`]: this.hasIcon,
100+
[`avatar-image`]: hasImage,
101+
[`avatar-icon`]: hasIcon,
102+
[`avatar-disabled`]: disabled,
96103
}}
97104
>
98105
<slot></slot>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
/**
5+
* Avatar does not test RTL behaviors.
6+
* Usages of Avatar in slots are tested in components that use Avatar.
7+
*/
8+
configs({ directions: ['ltr'], modes: ['ionic-md'] }).forEach(({ config, screenshot, title }) => {
9+
test.describe(title('avatar: states'), () => {
10+
test('should not have visual regressions', async ({ page }) => {
11+
await page.setContent(
12+
`
13+
<div id="container">
14+
<ion-avatar disabled> AV </ion-avatar>
15+
<ion-avatar disabled>
16+
<img src="/src/components/avatar/test/avatar.svg" />
17+
</ion-avatar>
18+
</div>
19+
`,
20+
config
21+
);
22+
const container = page.locator('#container');
23+
24+
await expect(container).toHaveScreenshot(screenshot(`avatar-disabled`));
25+
});
26+
});
27+
});
2.01 KB
Loading
2.99 KB
Loading
2.15 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Avatar - States</title>
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
9+
/>
10+
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
11+
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
12+
<script src="../../../../../scripts/testing/scripts.js"></script>
13+
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
14+
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
</head>
16+
17+
<body>
18+
<ion-app>
19+
<ion-header>
20+
<ion-toolbar>
21+
<ion-title>Avatar - States</ion-title>
22+
</ion-toolbar>
23+
</ion-header>
24+
25+
<ion-content>
26+
<h3>Disabled</h3>
27+
<ion-avatar disabled>AV</ion-avatar>
28+
<ion-avatar disabled>
29+
<img src="/src/components/avatar/test/avatar.svg" />
30+
</ion-avatar>
31+
</ion-content>
32+
</ion-app>
33+
</body>
34+
</html>

packages/angular/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ export declare interface IonApp extends Components.IonApp {}
211211

212212

213213
@ProxyCmp({
214-
inputs: ['mode', 'shape', 'size', 'theme']
214+
inputs: ['disabled', 'mode', 'shape', 'size', 'theme']
215215
})
216216
@Component({
217217
selector: 'ion-avatar',
218218
changeDetection: ChangeDetectionStrategy.OnPush,
219219
template: '<ng-content></ng-content>',
220220
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
221-
inputs: ['mode', 'shape', 'size', 'theme'],
221+
inputs: ['disabled', 'mode', 'shape', 'size', 'theme'],
222222
})
223223
export class IonAvatar {
224224
protected el: HTMLIonAvatarElement;

0 commit comments

Comments
 (0)