Skip to content

Commit

Permalink
fix(MobilePortraitNav): use single grid layout to prevent scroll posi…
Browse files Browse the repository at this point in the history
…tion resetting when a view is opened (#1719)

* fix(MobilePortraitNav): use single grid layout to prevent scroll position resetting when a view is opened

* fix(MobilePortraitNav): display views over header & footer to prevent size adjustments of the route ladder

* style: fix unintended whitespace changes

* fix: use appropriate mobile-portrait breakpoint, remove redundant width properties

* refactor: use minimal properties to define mobile portrait view styling

Co-authored-by: Brady <[email protected]>
  • Loading branch information
KaylaBrady and Brady authored Sep 13, 2022
1 parent 467a71a commit f3f2e36
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
5 changes: 0 additions & 5 deletions assets/css/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
height: 100%;
}

.m-nav--narrow.m-nav--covered {
grid-template-rows: minmax(0, 1fr);
grid-template-areas: "content";
}

.m-nav__nav-bar {
z-index: 1100;
}
Expand Down
4 changes: 4 additions & 0 deletions assets/css/_notification_drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
@media screen and (max-width: $mobile-max-width) {
width: 100%;
}
@media screen and (max-width: $mobile-portrait-max-width) {
position: fixed;
bottom: 0;
}
}

.m-notification-drawer__content {
Expand Down
4 changes: 4 additions & 0 deletions assets/css/_properties_panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
width: 100%;
}
}
@media screen and (max-width: $mobile-portrait-max-width) {
position: fixed;
bottom: 0;
}
}

.m-properties-panel .m-properties-panel__header-wrapper {
Expand Down
5 changes: 5 additions & 0 deletions assets/css/_swings_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
}
}
}
@media screen and (max-width: $mobile-portrait-max-width) {
position: fixed;
bottom: 0;
width: 100vw;
}
}

.m-swings-view__table-container {
Expand Down
1 change: 1 addition & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$non-mobile-min-width: 768px;
$mobile-max-width: $non-mobile-min-width - 1;
$mobile-portrait-max-width: 480px;
$tab-bar-width: 3rem;
$drawer-tab-width: 2rem;
$route-picker-width: 21.875rem;
Expand Down
54 changes: 29 additions & 25 deletions assets/src/components/nav/mobilePortraitNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,37 @@ const MobilePortraitNav = ({
const { mobileMenuIsOpen, routeTabs, openView, selectedVehicleOrGhost } =
state

if (openView !== OpenView.None || selectedVehicleOrGhost) {
return (
<div className="m-nav--narrow m-nav--covered">
<div className="m-nav__app-content">{children}</div>
const isViewOpen = openView !== OpenView.None || selectedVehicleOrGhost

const navVisibilityStyle = isViewOpen ? "hidden" : "visible"

return (
<div className="m-nav--narrow">
<div
className="m-nav__nav-bar m-nav__nav-bar--top"
style={{ visibility: navVisibilityStyle }}
>
<TopNavMobile
toggleMobileMenu={() => dispatch(toggleMobileMenu())}
openNotificationDrawer={() => dispatch(openNotificationDrawer())}
routeTabs={routeTabs}
mobileMenuIsOpen={mobileMenuIsOpen}
/>
</div>
)
} else {
return (
<div className="m-nav--narrow">
<div className="m-nav__nav-bar m-nav__nav-bar--top">
<TopNavMobile
toggleMobileMenu={() => dispatch(toggleMobileMenu())}
openNotificationDrawer={() => dispatch(openNotificationDrawer())}
routeTabs={routeTabs}
mobileMenuIsOpen={mobileMenuIsOpen}
/>
</div>
<div className="m-nav__app-content">{children}</div>
<div className="m-nav__nav-bar m-nav__nav-bar--bottom">
<BottomNavMobile
mobileMenuIsOpen={mobileMenuIsOpen}
openSwingsView={() => dispatch(openSwingsView())}
/>
</div>

<div className="m-nav__app-content">{children}</div>

<div
className="m-nav__nav-bar m-nav__nav-bar--bottom"
style={{ visibility: navVisibilityStyle }}
>
<BottomNavMobile
mobileMenuIsOpen={mobileMenuIsOpen}
openSwingsView={() => dispatch(openSwingsView())}
/>
</div>
)
}
</div>
)
}

export default MobilePortraitNav
18 changes: 10 additions & 8 deletions assets/tests/components/nav/mobilePortraitNav.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react"
import { render } from "@testing-library/react"
import "@testing-library/jest-dom"

import MobilePortraitNav from "../../../src/components/nav/mobilePortraitNav"
import { StateDispatchProvider } from "../../../src/contexts/stateDispatchContext"
import { initialState, OpenView } from "../../../src/state"
Expand All @@ -17,8 +19,8 @@ describe("MobilePortraitNav", () => {
</StateDispatchProvider>
)

expect(result.queryByTitle("Swings View")).not.toBeNull()
expect(result.queryByTitle("Notifications")).not.toBeNull()
expect(result.queryByTitle("Swings View")).toBeVisible()
expect(result.queryByTitle("Notifications")).toBeVisible()
})

test("doesn't render top / bottom nav when a view is open", () => {
Expand All @@ -34,8 +36,8 @@ describe("MobilePortraitNav", () => {
</StateDispatchProvider>
)

expect(result.queryByTitle("Swings View")).toBeNull()
expect(result.queryByTitle("Notifications")).toBeNull()
expect(result.queryByTitle("Swings View")).not.toBeVisible()
expect(result.queryByTitle("Notifications")).not.toBeVisible()
})

test("doesn't render top / bottom nav when a vehicle is selected", () => {
Expand All @@ -54,8 +56,8 @@ describe("MobilePortraitNav", () => {
</StateDispatchProvider>
)

expect(result.queryByTitle("Swings View")).toBeNull()
expect(result.queryByTitle("Notifications")).toBeNull()
expect(result.queryByTitle("Swings View")).not.toBeVisible()
expect(result.queryByTitle("Notifications")).not.toBeVisible()
})

test("doesn't render top / bottom nav when notification drawer is open", () => {
Expand All @@ -74,7 +76,7 @@ describe("MobilePortraitNav", () => {
</StateDispatchProvider>
)

expect(result.queryByTitle("Swings View")).toBeNull()
expect(result.queryByTitle("Notifications")).toBeNull()
expect(result.queryByTitle("Swings View")).not.toBeVisible()
expect(result.queryByTitle("Notifications")).not.toBeVisible()
})
})

0 comments on commit f3f2e36

Please sign in to comment.