Repository navigation
feat(split-pane): resolve breakpoints from config #31521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+357
−15
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Split Pane - When</title> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
| /> | ||
| <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" /> | ||
| <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" /> | ||
| <script> | ||
| /** | ||
| * Override the global screen breakpoints. `md` is moved well below its | ||
| * default of 768 so a viewport that would only match `xs` or `sm` by | ||
| * default matches `md` here. | ||
| * | ||
| * This must run before `scripts.js` and the Ionic bundle so the values | ||
| * are picked up by `initialize()`. | ||
| */ | ||
| const SCREEN_BREAKPOINTS = { | ||
| xs: 0, | ||
| sm: 200, | ||
| md: 400, | ||
| lg: 600, | ||
| xl: 800, | ||
| xxl: 1000, | ||
| }; | ||
|
|
||
| window.Ionic = { | ||
| config: { | ||
| screenBreakpoints: SCREEN_BREAKPOINTS, | ||
| }, | ||
| }; | ||
| </script> | ||
| <script src="../../../../../scripts/testing/scripts.js"></script> | ||
| <script nomodule src="../../../../../dist/ionic/ionic.js"></script> | ||
| <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> | ||
| <style> | ||
| /* Stays on screen while the window is resized */ | ||
| #breakpoint-readout { | ||
| position: fixed; | ||
| z-index: 100; | ||
|
|
||
| /* A heads-up display: it overlays the demo but never blocks it */ | ||
| pointer-events: none; | ||
|
|
||
| inset-block-end: 16px; | ||
| inset-inline-end: 16px; | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
|
|
||
| min-width: 92px; | ||
| padding: 10px 14px; | ||
|
|
||
| border-radius: 10px; | ||
|
|
||
| background-color: #1b1b1b; | ||
| box-shadow: 0 2px 10px rgb(0 0 0 / 35%); | ||
|
|
||
| color: #fff; | ||
| font-family: monospace; | ||
| line-height: 1.1; | ||
| } | ||
|
|
||
| #active-breakpoint { | ||
| font-size: 2rem; | ||
| font-weight: bold; | ||
| letter-spacing: 0.05em; | ||
| } | ||
|
|
||
| #breakpoint-readout small { | ||
| opacity: 0.7; | ||
| font-size: 0.8rem; | ||
| } | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
| <ion-app> | ||
| <ion-split-pane id="split-pane" when="md" content-id="main"> | ||
| <ion-menu side="start" content-id="main"> | ||
| <ion-content class="ion-padding">Menu</ion-content> | ||
| </ion-menu> | ||
|
|
||
| <div class="ion-page" id="main"> | ||
| <ion-content class="ion-padding"> | ||
| Main content. The split pane is shown at <code>md</code> and above, which this page configures as 400px. | ||
| </ion-content> | ||
| </div> | ||
| </ion-split-pane> | ||
|
|
||
| <div id="breakpoint-readout" aria-live="polite"> | ||
| <span id="active-breakpoint">…</span> | ||
| <small><span id="viewport-width">–</span>px</small> | ||
| </div> | ||
| </ion-app> | ||
|
|
||
| <script> | ||
| /** | ||
| * Resolve the active breakpoint from the same map the config was set | ||
| * from, so the readout cannot drift from what the components resolve. | ||
| * The largest matching breakpoint wins, which is how a `min-width` | ||
| * query resolves. | ||
| */ | ||
| const label = document.getElementById('active-breakpoint'); | ||
| const width = document.getElementById('viewport-width'); | ||
|
|
||
| const getActiveBreakpoint = () => { | ||
| return Object.keys(SCREEN_BREAKPOINTS) | ||
| .filter((breakpoint) => window.matchMedia(`(min-width: ${SCREEN_BREAKPOINTS[breakpoint]}px)`).matches) | ||
| .pop(); | ||
| }; | ||
|
|
||
| const showActiveBreakpoint = () => { | ||
| label.textContent = getActiveBreakpoint() ?? 'none'; | ||
| width.textContent = window.innerWidth; | ||
| }; | ||
|
|
||
| window.addEventListener('resize', showActiveBreakpoint); | ||
|
|
||
| customElements.whenDefined('ion-split-pane').then(showActiveBreakpoint); | ||
| </script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the default is now
lg, a config that arrives late leaves this query at the default width, becauseupdateStateonly runs on load and whenwhenordisabledchange. Could split pane also re-runupdateStatewhen the breakpoints change, like grid and col do withonBreakpointChange?