Skip to content

Commit 331c08a

Browse files
fix(fab): apply safe area in positioning to proper side regardless of direction (#28377)
Issue number: Internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> When calculating the fab's horizontal position, the safe area is taken into account. However, which safe area side is applied changes depending on whether the document's direction is LTR or RTL. This is incorrect as the left safe area padding will always be on the left side regardless of direction, and vice versa. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> The left safe area is always applied to the fab's `left` position, and vice versa. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent c801e2a commit 331c08a

14 files changed

+92
-6
lines changed

core/src/components/fab/fab.scss

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,29 @@
2323
}
2424

2525
:host(.fab-horizontal-start) {
26-
@include position-horizontal(
27-
calc(#{$fab-content-margin} + var(--ion-safe-area-left, 0px)), null
28-
);
26+
/* stylelint-disable */
27+
@include ltr() {
28+
left: calc(#{$fab-content-margin} + var(--ion-safe-area-left, 0px));
29+
}
30+
31+
@include rtl() {
32+
right: calc(#{$fab-content-margin} + var(--ion-safe-area-right, 0px));
33+
left: unset;
34+
}
35+
/* stylelint-enable */
2936
}
3037

3138
:host(.fab-horizontal-end) {
32-
@include position-horizontal(
33-
null, calc(#{$fab-content-margin} + var(--ion-safe-area-right, 0px))
34-
);
39+
/* stylelint-disable */
40+
@include ltr() {
41+
right: calc(#{$fab-content-margin} + var(--ion-safe-area-right, 0px));
42+
}
43+
44+
@include rtl() {
45+
left: calc(#{$fab-content-margin} + var(--ion-safe-area-left, 0px));
46+
right: unset;
47+
}
48+
/* stylelint-enable */
3549
}
3650

3751

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
configs({ modes: ['md'] }).forEach(({ title, screenshot, config }) => {
5+
test.describe(title('fab: safe area'), () => {
6+
test('should ignore document direction in safe area positioning for start-positioned fab', async ({ page }) => {
7+
await page.setContent(
8+
`
9+
<style>
10+
:root {
11+
--ion-safe-area-left: 40px;
12+
--ion-safe-area-right: 20px;
13+
}
14+
</style>
15+
16+
<ion-content>
17+
<ion-fab vertical="center" horizontal="start">
18+
<ion-fab-button>
19+
<ion-icon name="add"></ion-icon>
20+
</ion-fab-button>
21+
</ion-fab>
22+
</ion-content>
23+
`,
24+
config
25+
);
26+
27+
/**
28+
* We need to capture the entire page to check the fab's position,
29+
* but we don't need much extra white space.
30+
*/
31+
await page.setViewportSize({
32+
width: 200,
33+
height: 200,
34+
});
35+
36+
await expect(page).toHaveScreenshot(screenshot('fab-safe-area-horizontal-start'));
37+
});
38+
39+
test('should ignore document direction in safe area positioning for end-positioned fab', async ({ page }) => {
40+
await page.setContent(
41+
`
42+
<style>
43+
:root {
44+
--ion-safe-area-left: 40px;
45+
--ion-safe-area-right: 20px;
46+
}
47+
</style>
48+
49+
<ion-content>
50+
<ion-fab vertical="center" horizontal="end">
51+
<ion-fab-button>
52+
<ion-icon name="add"></ion-icon>
53+
</ion-fab-button>
54+
</ion-fab>
55+
</ion-content>
56+
`,
57+
config
58+
);
59+
60+
/**
61+
* We need to capture the entire page to check the fab's position,
62+
* but we don't need much extra white space.
63+
*/
64+
await page.setViewportSize({
65+
width: 200,
66+
height: 200,
67+
});
68+
69+
await expect(page).toHaveScreenshot(screenshot('fab-safe-area-horizontal-end'));
70+
});
71+
});
72+
});
3.73 KB
Loading
5.73 KB
Loading
3.38 KB
Loading
3.75 KB
Loading
5.6 KB
Loading
3.38 KB
Loading
3.75 KB
Loading
5.6 KB
Loading

0 commit comments

Comments
 (0)