Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/css/float-elements.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Global stylesheet: `:host-context()` never matches outside a shadow root
$rtl-use-host-context: false;

@import "../themes/ionic.globals";
@import "../themes/ionic.mixins";

Expand Down
38 changes: 38 additions & 0 deletions core/src/css/test/global-stylesheets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { execFileSync } from 'child_process';
import { readdirSync } from 'fs';
import { dirname, join } from 'path';

const cssDir = join(__dirname, '..');
const sassCli = join(dirname(require.resolve('sass')), 'sass.js');

/**
* Compiles through the sass CLI, the same way `npm run css.sass` builds
* the published stylesheets. The sass JS API can't be imported here
* because it detects the spec window and never populates its exports.
*/
const compileStylesheet = (file: string) =>
execFileSync(process.execPath, [sassCli, '--style=compressed', '--no-source-map', join(cssDir, file)], {
encoding: 'utf8',
});

const globalStylesheets = ['.', 'palettes'].flatMap((dir) =>
readdirSync(join(cssDir, dir))
.filter((file) => file.endsWith('.scss'))
.map((file) => join(dir, file))
);

describe('global stylesheets', () => {
// https://github.com/ionic-team/ionic-framework/issues/30024
it.each(globalStylesheets)('%s should not contain :host-context', (file) => {
expect(compileStylesheet(file)).not.toContain(':host-context');
});

it('float-elements.scss should flip start and end floats for an ancestor dir=rtl', () => {
const css = compileStylesheet('float-elements.scss');

expect(css).toContain('[dir=rtl] .ion-float-start{float:right !important}');
expect(css).toContain('[dir=rtl] .ion-float-end{float:left !important}');
expect(css).toContain('.ion-float-start:dir(rtl){float:right !important}');
expect(css).toContain('.ion-float-end:dir(rtl){float:left !important}');
});
});
7 changes: 6 additions & 1 deletion core/src/themes/ionic.mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@
// }
}

// Whether `rtl()` emits `:host-context()` selectors. Global stylesheets
// set this to false: they apply to the document, where `:host-context()`
// never matches, and Lightning CSS warns about every occurrence.
$rtl-use-host-context: true !default;

@mixin rtl() {
$root: #{&};

Expand Down Expand Up @@ -254,7 +259,7 @@
}

// Supported by Chrome.
@if length($hostContextSelectors) > 0 {
@if $rtl-use-host-context and length($hostContextSelectors) > 0 {
@at-root #{$hostContextSelectors} {
@content;
}
Expand Down
Loading