-
Notifications
You must be signed in to change notification settings - Fork 86
fix: restore icon size workaround for Safari 26 #10296
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3471676
Revert "refactor: remove no longer needed icon Safari workaround (#93…
DiegoCardoso 7dadd9c
refactor: add check for icon inside an element with shadow root
DiegoCardoso 99b636a
refactor: use `updated` Lit livecycle
DiegoCardoso 525ab53
refactor: replace usage of registerStyles with css literal
web-padawan 011df55
fix: apply styles in the correct order
web-padawan b73a3e0
test: add icon with char in test
DiegoCardoso 57e8ab0
Update packages/icon/src/vaadin-icon-font-size-mixin.js
DiegoCardoso b6fcd06
add newline
DiegoCardoso 0fc5a45
clarify mixin in jsdoc
DiegoCardoso a58c308
chore: align .d.ts comment
web-padawan 8d0f368
chore: align copyright year
web-padawan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2021 - 2025 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import type { Constructor } from '@open-wc/dedupe-mixin'; | ||
|
||
/** | ||
* Mixin which enables the font icon sizing fallback for browsers that do not support CSS Container Queries. | ||
* In older versions of Safari, it didn't support Container Queries units used in pseudo-elements. It has been fixed in | ||
* recent versions, but there's an regression in Safari 26, which caused the same issue to happen when the icon is | ||
* attached to an element with shadow root. | ||
* The mixin does nothing if the browser supports CSS Container Query units for pseudo elements. | ||
*/ | ||
export declare function IconFontSizeMixin<T extends Constructor<HTMLElement>>( | ||
base: T, | ||
): Constructor<IconFontSizeMixinClass> & T; | ||
|
||
export declare class IconFontSizeMixinClass {} |
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,64 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2021 - 2025 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { css } from 'lit'; | ||
import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js'; | ||
import { needsFontIconSizingFallback } from './vaadin-icon-helpers.js'; | ||
|
||
const usesFontIconSizingFallback = needsFontIconSizingFallback(); | ||
|
||
/** | ||
* Mixin which enables the font icon sizing fallback for browsers that do not support CSS Container Queries. | ||
web-padawan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* In older versions of Safari, it didn't support Container Queries units used in pseudo-elements. It has been fixed in | ||
* recent versions, but there's an regression in Safari 26, which caused the same issue to happen when the icon is | ||
* attached to an element with shadow root. | ||
* The mixin does nothing if the browser supports CSS Container Query units for pseudo elements. | ||
* | ||
* @polymerMixin | ||
*/ | ||
export const IconFontSizeMixin = (superclass) => | ||
!usesFontIconSizingFallback | ||
? superclass | ||
: class extends ResizeMixin(superclass) { | ||
static get styles() { | ||
return css` | ||
:host::after, | ||
:host::before { | ||
font-size: var(--vaadin-icon-visual-size, var(--_vaadin-font-icon-size)); | ||
} | ||
`; | ||
} | ||
|
||
/** @protected */ | ||
updated(props) { | ||
super.updated(props); | ||
|
||
if (props.has('char') || props.has('iconClass') || props.has('ligature')) { | ||
this.__updateFontIconSize(); | ||
} | ||
} | ||
|
||
/** | ||
* @protected | ||
* @override | ||
*/ | ||
_onResize() { | ||
// Update when the element is resized | ||
this.__updateFontIconSize(); | ||
} | ||
|
||
/** | ||
* Updates the --_vaadin-font-icon-size CSS variable value if font icons are used. | ||
* | ||
* @private | ||
*/ | ||
__updateFontIconSize() { | ||
if (this.char || this.iconClass || this.ligature) { | ||
const { paddingTop, paddingBottom, height } = getComputedStyle(this); | ||
const fontIconSize = parseFloat(height) - parseFloat(paddingTop) - parseFloat(paddingBottom); | ||
this.style.setProperty('--_vaadin-font-icon-size', `${fontIconSize}px`); | ||
} | ||
} | ||
}; |
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,61 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2021 - 2025 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
*/ | ||
import { isSafari } from '@vaadin/component-base/src/browser-utils.js'; | ||
|
||
/** | ||
* Checks if the current browser supports CSS Container Query units for pseudo elements. | ||
* i.e. if the fix for https://bugs.webkit.org/show_bug.cgi?id=253939 is available. | ||
*/ | ||
export function supportsCQUnitsForPseudoElements() { | ||
const testStyle = document.createElement('style'); | ||
testStyle.textContent = ` | ||
.vaadin-icon-test-element { | ||
container-type: size; | ||
height: 2px; | ||
visibility: hidden; | ||
position: fixed; | ||
} | ||
|
||
.vaadin-icon-test-element::before { | ||
content: ''; | ||
display: block; | ||
height: 100cqh; | ||
`; | ||
const testElement = document.createElement('div'); | ||
testElement.classList.add('vaadin-icon-test-element'); | ||
|
||
const shadowParent = document.createElement('div'); | ||
shadowParent.attachShadow({ mode: 'open' }); | ||
shadowParent.shadowRoot.innerHTML = '<slot></slot>'; | ||
shadowParent.append(testElement.cloneNode()); | ||
|
||
document.body.append(testStyle, testElement, shadowParent); | ||
|
||
const needsFallback = [...document.querySelectorAll('.vaadin-icon-test-element')].find( | ||
(el) => getComputedStyle(el, '::before').height !== '2px', | ||
); | ||
|
||
testStyle.remove(); | ||
testElement.remove(); | ||
shadowParent.remove(); | ||
return !needsFallback; | ||
} | ||
|
||
/** | ||
* Checks if the current browser needs a fallback for sizing font icons instead of relying on CSS Container Queries. | ||
*/ | ||
export function needsFontIconSizingFallback() { | ||
if (!CSS.supports('container-type: inline-size')) { | ||
// The browser does not support CSS Container Queries at all. | ||
return true; | ||
} | ||
if (!isSafari) { | ||
// Browsers other than Safari support CSS Container Queries as expected. | ||
return false; | ||
} | ||
// Check if the browser does not support CSS Container Query units for pseudo elements. | ||
return !supportsCQUnitsForPseudoElements(); | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.