-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(toolbar): add titlePlacement prop to control title position relative to content #31034
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
Draft
brandyscarney
wants to merge
6
commits into
next
Choose a base branch
from
FW-7054
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−10
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32d5e4e
feat(toolbar): add titlePlacement property to determine how to align …
brandyscarney e9480e9
test(toolbar): add e2e test for title placement
brandyscarney 77583dd
chore(): add updated snapshots
brandyscarney d2ae878
Merge branch 'next' into FW-7054
brandyscarney eac4475
chore: build
brandyscarney 4421028
fix(toolbar): only apply text-align to slotted title
brandyscarney 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
133 changes: 133 additions & 0 deletions
133
core/src/components/toolbar/test/title-placement/index.html
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,133 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Toolbar - Title Placement</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 src="../../../../../scripts/testing/scripts.js"></script> | ||
| <script nomodule src="../../../../../dist/ionic/ionic.js"></script> | ||
| <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <ion-app> | ||
| <ion-header id="default-placement"> | ||
| <ion-toolbar> | ||
| <ion-title>Default Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar> | ||
| <ion-buttons slot="start"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="menu"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| <ion-title>Default Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar> | ||
| <ion-title>Default Placement</ion-title> | ||
| <ion-buttons slot="primary"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="search"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-header> | ||
| <ion-toolbar title-placement="start"> | ||
| <ion-title>Start Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="start"> | ||
| <ion-buttons slot="start"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="menu"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| <ion-title>Start Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="start"> | ||
| <ion-title>Start Placement</ion-title> | ||
| <ion-buttons slot="primary"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="search"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-header> | ||
| <ion-toolbar title-placement="center"> | ||
| <ion-title>Center Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="center"> | ||
| <ion-buttons slot="start"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="menu"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| <ion-title>Center Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="center"> | ||
| <ion-title>Center Placement</ion-title> | ||
| <ion-buttons slot="primary"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="search"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-header> | ||
| <ion-toolbar title-placement="end"> | ||
| <ion-title>End Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="end"> | ||
| <ion-buttons slot="start"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="menu"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| <ion-title>End Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="end"> | ||
| <ion-title>End Placement</ion-title> | ||
| <ion-buttons slot="primary"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="search"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
|
|
||
| <ion-footer> | ||
| <ion-button onclick="toggleTitlePlacement('start')">Start</ion-button> | ||
| <ion-button onclick="toggleTitlePlacement('center')">Center</ion-button> | ||
| <ion-button onclick="toggleTitlePlacement('end')">End</ion-button> | ||
| </ion-footer> | ||
| </ion-app> | ||
|
|
||
| <script> | ||
| const defaultPlacementToolbars = document.querySelectorAll('#default-placement ion-toolbar'); | ||
|
|
||
| function toggleTitlePlacement(placement) { | ||
| defaultPlacementToolbars.forEach((toolbar) => { | ||
| toolbar.titlePlacement = placement; | ||
| }); | ||
| } | ||
| </script> | ||
|
|
||
| <style> | ||
| ion-footer { | ||
| display: flex; | ||
|
|
||
| justify-content: center; | ||
| align-items: center; | ||
|
|
||
| gap: 10px; | ||
| padding: 8px; | ||
| } | ||
| </style> | ||
| </body> | ||
| </html> |
45 changes: 45 additions & 0 deletions
45
core/src/components/toolbar/test/title-placement/toolbar.e2e.ts
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,45 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { configs, test } from '@utils/test/playwright'; | ||
|
|
||
| /** | ||
| * Title placement is only supported by the `ionic` theme. | ||
| */ | ||
| configs({ modes: ['ionic-md'] }).forEach(({ title, screenshot, config }) => { | ||
| test.describe(title('toolbar: title-placement'), () => { | ||
| ['start', 'center', 'end'].forEach((placement) => { | ||
| test(`should not have visual regressions with ${placement} placement`, async ({ page }) => { | ||
| const placementTitle = placement.charAt(0).toUpperCase() + placement.slice(1); | ||
|
|
||
| await page.setContent( | ||
| ` | ||
| <ion-header> | ||
| <ion-toolbar title-placement="${placement}"> | ||
| <ion-title>${placementTitle} Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="${placement}"> | ||
| <ion-buttons slot="start"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="menu"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| <ion-title>${placementTitle} Placement</ion-title> | ||
| </ion-toolbar> | ||
| <ion-toolbar title-placement="${placement}"> | ||
| <ion-title>${placementTitle} Placement</ion-title> | ||
| <ion-buttons slot="primary"> | ||
| <ion-button> | ||
| <ion-icon slot="icon-only" name="search"></ion-icon> | ||
| </ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| `, | ||
| config | ||
| ); | ||
|
|
||
| const header = page.locator('ion-header'); | ||
| await expect(header).toHaveScreenshot(screenshot(`toolbar-title-placement-${placement}`)); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Binary file added
BIN
+5.85 KB
...shots/toolbar-title-placement-center-ionic-md-ltr-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.81 KB
...hots/toolbar-title-placement-center-ionic-md-ltr-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...shots/toolbar-title-placement-center-ionic-md-ltr-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.85 KB
...shots/toolbar-title-placement-center-ionic-md-rtl-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.8 KB
...hots/toolbar-title-placement-center-ionic-md-rtl-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
...shots/toolbar-title-placement-center-ionic-md-rtl-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.51 KB
...napshots/toolbar-title-placement-end-ionic-md-ltr-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.22 KB
...apshots/toolbar-title-placement-end-ionic-md-ltr-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.12 KB
...napshots/toolbar-title-placement-end-ionic-md-ltr-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.54 KB
...napshots/toolbar-title-placement-end-ionic-md-rtl-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.32 KB
...apshots/toolbar-title-placement-end-ionic-md-rtl-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.41 KB
...napshots/toolbar-title-placement-end-ionic-md-rtl-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.02 KB
...pshots/toolbar-title-placement-start-ionic-md-ltr-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.41 KB
...shots/toolbar-title-placement-start-ionic-md-ltr-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...pshots/toolbar-title-placement-start-ionic-md-ltr-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.02 KB
...pshots/toolbar-title-placement-start-ionic-md-rtl-light-Mobile-Chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.96 KB
...shots/toolbar-title-placement-start-ionic-md-rtl-light-Mobile-Firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.8 KB
...pshots/toolbar-title-placement-start-ionic-md-rtl-light-Mobile-Safari-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import type { ComponentInterface } from '@stencil/core'; | ||
| import { Component, Element, forceUpdate, h, Host, Listen, Prop } from '@stencil/core'; | ||
| import { Component, Element, forceUpdate, h, Host, Listen, Prop, Watch } from '@stencil/core'; | ||
| import { createColorClasses, hostContext } from '@utils/theme'; | ||
|
|
||
| import { getIonTheme } from '../../global/ionic-global'; | ||
|
|
@@ -30,6 +30,14 @@ import type { Color, CssClassMap, StyleEventDetail } from '../../interface'; | |
| }) | ||
| export class Toolbar implements ComponentInterface { | ||
| private childrenStyles = new Map<string, CssClassMap>(); | ||
| private readonly slotClasses = [ | ||
| 'has-start-content', | ||
| 'has-end-content', | ||
| 'has-primary-content', | ||
| 'has-secondary-content', | ||
| ]; | ||
| private readonly showClasses = ['show-start', 'show-end', 'show-primary', 'show-secondary']; | ||
| private readonly slotSizeVars = ['--start-end-size', '--primary-secondary-size']; | ||
|
|
||
| @Element() el!: HTMLIonToolbarElement; | ||
|
|
||
|
|
@@ -40,6 +48,14 @@ export class Toolbar implements ComponentInterface { | |
| */ | ||
| @Prop({ reflect: true }) color?: Color; | ||
|
|
||
| /** | ||
| * Where to place the title relative to the other toolbar content. | ||
| * `"start"`: The title will appear to the left of the toolbar content in LTR and to the right in RTL. | ||
| * `"center"`: The title will appear in the center of the toolbar. | ||
| * `"end"`: The title will appear to the right of the toolbar content in LTR and to the left in RTL. | ||
| */ | ||
| @Prop() titlePlacement?: 'start' | 'center' | 'end'; | ||
|
|
||
| componentWillLoad() { | ||
| const buttons = Array.from(this.el.querySelectorAll('ion-buttons')); | ||
|
|
||
|
|
@@ -67,6 +83,24 @@ export class Toolbar implements ComponentInterface { | |
| this.updateSlotWidths(); | ||
| } | ||
|
|
||
| @Watch('titlePlacement') | ||
| titlePlacementChanged() { | ||
| this.updateSlotClasses(); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the title placement. | ||
| * Returns the title placement if it is set, otherwise returns `"center"` | ||
| * for `ionic` and `ios`, and `"start"` for `md`. | ||
| */ | ||
| private getTitlePlacement(): 'start' | 'center' | 'end' { | ||
| if (this.titlePlacement !== undefined) { | ||
| return this.titlePlacement; | ||
| } | ||
|
|
||
| return getIonTheme(this) === 'ionic' || getIonTheme(this) === 'ios' ? 'center' : 'start'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this property doesn't work with |
||
| } | ||
|
|
||
| /** | ||
| * Updates the CSS custom properties for slot widths | ||
| * This ensures that slots shown by their met conditions | ||
|
|
@@ -164,7 +198,21 @@ export class Toolbar implements ComponentInterface { | |
| return allMeasurementsSuccessful; | ||
| } | ||
|
|
||
| /** | ||
| * Removes all slot visibility classes and slot width CSS variables. | ||
| */ | ||
| private removeSlotClasses() { | ||
| this.el.classList.remove(...this.slotClasses, ...this.showClasses); | ||
| this.slotSizeVars.forEach((cssVar) => this.el.style.removeProperty(cssVar)); | ||
| } | ||
|
|
||
| private updateSlotClasses() { | ||
| const titlePlacement = this.getTitlePlacement(); | ||
| if (titlePlacement !== 'center') { | ||
| this.removeSlotClasses(); | ||
| return; | ||
| } | ||
|
|
||
| // Check if slots have content | ||
| const slots = ['start', 'end', 'primary', 'secondary']; | ||
|
|
||
|
|
@@ -250,12 +298,15 @@ export class Toolbar implements ComponentInterface { | |
| Object.assign(childStyles, style); | ||
| }); | ||
|
|
||
| const titlePlacement = this.getTitlePlacement(); | ||
|
|
||
| return ( | ||
| <Host | ||
| class={{ | ||
| ...createColorClasses(this.color, { | ||
| [theme]: true, | ||
| 'in-toolbar': hostContext('ion-toolbar', this.el), | ||
| [`toolbar-title-placement-${titlePlacement}`]: true, | ||
| }), | ||
| ...childStyles, | ||
| }} | ||
|
|
||
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
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.
I chose to add
titlePlacementto the toolbar because it controls all the positioning logic, but if we would prefer to addplacementas a property onion-titlewe could assign it there and pass it up toion-toolbar.