Skip to content

Commit

Permalink
fix(rtl): mixins work with pseudo elements
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 370770101
  • Loading branch information
asyncLiz authored and Copybara-Service committed Apr 27, 2021
1 parent c8edee5 commit f5b6110
Show file tree
Hide file tree
Showing 7 changed files with 597 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/mdc-rtl/_rtl.scss
Expand Up @@ -25,7 +25,9 @@

@use 'sass:list';
@use 'sass:meta';
@use 'sass:selector';
@use '@material/theme/theme';
@use '@material/theme/selector-ext';

$include: true !default;

Expand Down Expand Up @@ -70,9 +72,17 @@ $include: true !default;
/// @content Content to be styled in an RTL context.
@mixin rtl() {
@if ($include) {
[dir='rtl'] &,
&[dir='rtl'] {
@content;
$dir-rtl: '[dir=rtl]';

$rtl-selectors: list.join(
selector.nest($dir-rtl, &),
selector-ext.append-strict(&, $dir-rtl)
);

@at-root {
#{$rtl-selectors} {
@content;
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions packages/mdc-rtl/test/rtl.scss.test.ts
@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2020 Google Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import * as fs from 'fs';
import * as path from 'path';

describe('rtl.test.scss', () => {
let css = '';

beforeAll(() => {
const filePath = path.join(__dirname, 'rtl.test.css');
css = fs.readFileSync(filePath, 'utf8').trim();
});

it('should not add [dir=rtl] after pseudo element', () => {
expect(css).not.toContain('.test-pseudo-element::before[dir=rtl]');
expect(css).toContain('.test-pseudo-element[dir=rtl]::before');
});
});
9 changes: 9 additions & 0 deletions packages/mdc-rtl/test/rtl.test.scss
@@ -0,0 +1,9 @@
@use '../rtl';

.test-pseudo-element {
&::before {
@include rtl.rtl {
margin-right: 0;
}
}
}

0 comments on commit f5b6110

Please sign in to comment.