Skip to content

Commit

Permalink
fix(fab-button): position is correct with custom sizes (#28195)
Browse files Browse the repository at this point in the history
Issue number: resolves #22564

---------

<!-- 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. -->

Changing the size of the FAB button causes it to be positioned
incorrectly. This was happening because we set position values based on
the assumption that the default FAB button would always be 56px x 56px.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- FAB and FAB List positioning is now computed based on intrinsic size

## 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. -->

Dev build: `7.4.1-dev.11695395641.14897417`

---------

Co-authored-by: ionitron <[email protected]>
  • Loading branch information
liamdebeasi and Ionitron authored Sep 28, 2023
1 parent 355d95d commit eb41b55
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/src/components/fab-button/fab-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
// --------------------------------------------------

:host(.fab-button-small) {
@include margin(($fab-size - $fab-small-size) * 0.5);
@include margin($fab-button-small-margin);

width: #{$fab-small-size};
height: #{$fab-small-size};
Expand Down
3 changes: 3 additions & 0 deletions core/src/components/fab-button/fab-button.vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ $fab-small-size: 40px !default;

/// @prop - Border radius of the FAB button
$fab-border-radius: 50% !default;

/// @prop - Margin applied to the small FAB button
$fab-button-small-margin: 8px !default;
17 changes: 12 additions & 5 deletions core/src/components/fab-list/fab-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// --------------------------------------------------

:host {
@include margin($fab-size + $fab-list-margin, 0);
@include margin(calc(100% + #{$fab-list-margin}), 0);

display: none;
position: absolute;
Expand All @@ -13,8 +13,15 @@
flex-direction: column;
align-items: center;

min-width: $fab-size;
min-height: $fab-size;
/**
* The list should be centered relative to the parent
* FAB button. We set minimum dimensions so the
* FAB list can be centered relative to the small FAB button.
* However, the small FAB button adds start/end margin, so we need
* to account for that in the FAB list dimensions.
*/
min-width: $fab-small-size + ($fab-button-small-margin * 2);
min-height: $fab-small-size + ($fab-button-small-margin * 2);
}

:host(.fab-list-active) {
Expand Down Expand Up @@ -59,14 +66,14 @@
}

:host(.fab-list-side-start) {
@include margin(0, $fab-size + $fab-list-margin);
@include margin(0, calc(100% + #{$fab-list-margin}));
@include position-horizontal(null, 0);

flex-direction: row-reverse;
}

:host(.fab-list-side-end) {
@include margin(0, $fab-size + $fab-list-margin);
@include margin(0, calc(100% + #{$fab-list-margin}));
@include position(null, null, null, 0);

flex-direction: row;
Expand Down
89 changes: 82 additions & 7 deletions core/src/components/fab/fab.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@import "./fab.vars";
@import "../fab-list/fab-list.vars";

// Floating Action Button Container
// --------------------------------------------------

:host {
position: absolute;

width: fit-content;
height: fit-content;

z-index: $z-index-fixed-content;
}

Expand All @@ -14,8 +18,8 @@
// --------------------------------------------------

:host(.fab-horizontal-center) {
@include position(null, null, null, 50%);
@include margin-horizontal(-$fab-size * 0.5, null);
@include position(null, 0px, null, 0px);
@include margin(null, auto);
}

:host(.fab-horizontal-start) {
Expand All @@ -38,22 +42,93 @@
top: $fab-content-margin;
}

/**
* Reset the top value since edge
* styles use margin-top.
*/
:host(.fab-vertical-top.fab-edge) {
top: -$fab-size * 0.5;
top: 0;
}

/**
* We need to adjust the parent FAB button up by half
* its height so that half of it sits on the header. As a result,
* we target the slotted ion-fab-button instead of targeting the host.
*/
:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-button) {
margin-top: -50%;
}

/**
* The small FAB button adds top and bottom margin. We need to account for
* that margin when we adjust the FAB button for edge styles since we
* are overriding the margin-top value below.
*/
:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-button.fab-button-small) {
margin-top: calc((-100% + $fab-button-small-margin * 2) / 2);
}

/**
* Since we are adjusting the FAB button we also need
* to adjust the sibling ion-fab-list otherwise there will be
* a gap between the parent FAB button and the associated list.
*/
:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-start),
:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-end) {
@include margin(-50%, null, null, null);
}

:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-top),
:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-bottom) {
@include margin(calc(50% + #{$fab-list-margin}) null, null, null);
}

:host(.fab-vertical-bottom) {
bottom: $fab-content-margin;
}

/**
* Reset the bottom value since edge
* styles use margin-bottom.
*/
:host(.fab-vertical-bottom.fab-edge) {
bottom: -$fab-size * 0.5;
bottom: 0;
}

/**
* We need to adjust the parent FAB button down by half
* its height so that half of it sits on the footer. As a result,
* we target the slotted ion-fab-button instead of targeting the host.
*/
:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-button) {
margin-bottom: -50%;
}

:host(.fab-vertical-center) {
@include margin(-$fab-size * 0.5, null, null, null);
/**
* The small FAB button adds top and bottom margin. We need to account for
* that margin when we adjust the FAB button for edge styles since we
* are overriding the margin-bottom value below.
*/
:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-button.fab-button-small) {
margin-bottom: calc((-100% + $fab-button-small-margin * 2) / 2);
}

/**
* Since we are adjusting the FAB button we also need
* to adjust the sibling ion-fab-list otherwise there will be
* a gap between the parent FAB button and the associated list.
*/
:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-start),
:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-end) {
@include margin(null, null, -50%, null);
}

:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-top),
:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-bottom) {
@include margin(null, null, calc(50% + #{$fab-list-margin}) null);
}

top: 50%;
:host(.fab-vertical-center) {
@include position(0px, null, 0px, null);
@include margin(auto, null);
}
17 changes: 17 additions & 0 deletions core/src/components/fab/test/custom-size/fab.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect } from '@playwright/test';
import { configs, test, Viewports } from '@utils/test/playwright';

/**
* This behavior does not vary across modes
*/
configs({ modes: ['ios'] }).forEach(({ title, config, screenshot }) => {
test.describe(title('fab: custom size'), () => {
test('should position fabs correctly with custom sizes', async ({ page }) => {
await page.goto(`/src/components/fab/test/custom-size`, config);

await page.setViewportSize(Viewports.tablet.landscape);

await expect(page).toHaveScreenshot(screenshot(`fab-custom-size`));
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit eb41b55

Please sign in to comment.