Files
ionic-framework/core/src/components/menu/menu.scss
Maria Hutt 574d762594 test(menu): safe area and proper var reset (#28177)
Issue number: N/A

---------

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

- There are no tests for menu when safe area is applied.
- The safe area variables on menu weren't being reset properly to allow
easy local customization.

Currently, some of the variables are being set to `env()`. This is the
same structure that is being used in core. However, this doesn't
prevents users from mocking the safe area when using
`--ion-safe-area-left: 50px` on `html`. It makes it hard to create tests
to validate that padding is being applied to the safe area.

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

- Tests have been added.
- The safe area variables on menu are now being reset to use the values
from `:root`.

The variables are being `unset` in order for the variables to [default
to parent styles](https://stackoverflow.com/a/69491310/5374225). Since
core styles has already declared the variables, then developers can use
`--ion-safe-area-left: 50px` on `html`.

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

N/A

---------

Co-authored-by: ionitron <hi@ionicframework.com>
2023-09-18 17:36:58 +00:00

203 lines
5.7 KiB
SCSS

@import "./menu.vars";
// Menu
// --------------------------------------------------
:host {
/**
* @prop --background: Background of the menu
*
* @prop --min-width: Minimum width of the menu
* @prop --width: Width of the menu
* @prop --max-width: Maximum width of the menu
*
* @prop --min-height: Minimum height of the menu
* @prop --height: Height of the menu
* @prop --max-height: Maximum height of the menu
*/
--width: #{$menu-width};
--min-width: auto;
--max-width: auto;
--height: 100%;
--min-height: auto;
--max-height: auto;
--background: #{$background-color};
@include position(0, 0, 0, 0);
display: none;
position: absolute;
contain: strict;
}
:host(.show-menu) {
display: block;
}
.menu-inner {
@include transform(translateX(-9999px));
display: flex;
position: absolute;
flex-direction: column;
justify-content: space-between;
width: var(--width);
min-width: var(--min-width);
max-width: var(--max-width);
height: var(--height);
min-height: var(--min-height);
max-height: var(--max-height);
background: var(--background);
contain: strict;
}
:host(.menu-side-start) .menu-inner {
/**
* Menu does not cover the whole screen so we need to set the safe area for the
* side that touches the screen edge only. Since safe area is not logical, it
* needs to be applied to the correct side depending on the language direction.
* Otherwise, the content will have less space on both sides.
*
* LTR:
* The left side of the menu touches the screen edge. The safe area padding has
* already been set in the core styles, so there's no need to set it again.
* The right side of the menu is not touching the screen edge. Padding is not
* applied to the right side of the menu. A value of 0 is set.
*/
--ion-safe-area-right: 0px;
@include position(0, auto, 0, 0);
@include rtl() {
/**
* Menu does not cover the whole screen so we need to set the safe area for the
* side that touches the screen edge only. Since safe area is not logical, it
* needs to be applied to the correct side depending on the language direction.
* Otherwise, the content will have less space on both sides.
*
* RTL:
* The right side of the menu touches the screen edge.
* The right side needs to revert back to the default value that was set in the core styles, so we unset it here.
* This would keep the variable consistent with the core styles.
* Additionally, it would continue to allow users to override the variable if they choose to.
* The left side of the menu is not touching the screen edge. Padding is not
* applied to the left side of the menu. A value of 0 is set.
*/
--ion-safe-area-right: unset;
--ion-safe-area-left: 0px;
}
}
:host(.menu-side-end) .menu-inner {
/**
* Menu does not cover the whole screen so we need to set the safe area for the
* side that touches the screen edge only. Since safe area is not logical, it
* needs to be applied to the correct side depending on the language direction.
* Otherwise, the content will have less space on both sides.
*
* LTR:
* The right side of the menu touches the screen edge. The safe area padding has
* already been set in the core styles, so there's no need to set it again.
* The left side of the menu is not touching the screen edge. Padding is not
* applied to the left side of the menu. A value of 0 is set.
*/
--ion-safe-area-left: 0px;
@include position(0, 0, 0, auto);
@include rtl() {
/**
* Menu does not cover the whole screen so we need to set the safe area for the
* side that touches the screen edge only. Since safe area is not logical, it
* needs to be applied to the correct side depending on the language direction.
* Otherwise, the content will have less space on both sides.
*
* RTL:
* The left side of the menu touches the screen edge.
* The left side needs to revert back to the default value that was set in the core styles, so we unset it here.
* This would keep the variable consistent with the core styles.
* Additionally, it would continue to allow users to override the variable if they choose to.
* The right side of the menu is not touching the screen edge. Padding is not
* applied to the right side of the menu. A value of 0 is set.
*/
--ion-safe-area-left: unset;
--ion-safe-area-right: 0px;
}
}
ion-backdrop {
display: none;
opacity: .01;
z-index: -1;
}
@media (max-width: 340px) {
.menu-inner {
--width: #{$menu-small-width};
}
}
// Menu Reveal
// --------------------------------------------------
// The content slides over to reveal the menu underneath.
// The menu itself, which is under the content, does not move.
:host(.menu-type-reveal) {
z-index: 0;
}
:host(.menu-type-reveal.show-menu) .menu-inner {
@include transform(translate3d(0, 0, 0));
}
// Menu Overlay
// --------------------------------------------------
// The menu slides over the content. The content
// itself, which is under the menu, does not move.
:host(.menu-type-overlay) {
z-index: $z-index-menu-overlay;
}
:host(.menu-type-overlay) .show-backdrop {
display: block;
cursor: pointer;
}
// Menu Split Pane
// --------------------------------------------------
:host(.menu-pane-visible) {
width: var(--width);
min-width: var(--min-width);
max-width: var(--max-width);
}
:host(.menu-pane-visible) .menu-inner {
@include position-horizontal(0, 0);
width: auto;
/* stylelint-disable declaration-no-important */
transform: none !important;
box-shadow: none !important;
}
:host(.menu-pane-visible) ion-backdrop {
display: hidden !important;
/* stylelint-enable declaration-no-important */
}