Skip to content

Commit

Permalink
fix: mode arg and add closed test
Browse files Browse the repository at this point in the history
  • Loading branch information
knownasilya committed Oct 4, 2020
1 parent 6277383 commit 3a25ed8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addon/components/shadow-dom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { action } from '@ember/object';
export default class ShadowDom extends Component {
@tracked shadow = null;

mode = 'open';
defaultMode = 'open';

@action
setupRoot(element) {
let mode = this.mode;
let mode = this.args.mode || this.defaultMode;
let shadow = element.attachShadow({ mode });

this.shadow = shadow;
Expand Down
6 changes: 5 additions & 1 deletion app/templates/components/shadow-dom.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<div {{did-insert this.setupRoot}} ...attributes></div>
<div
{{did-insert this.setupRoot}}
...attributes
></div>

{{#if this.shadow}}
{{#-in-element this.shadow}}
{{yield}}
Expand Down
12 changes: 11 additions & 1 deletion tests/integration/components/shadow-dom/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ module('Integration | Component | shadow-dom', function(hooks) {

test('it renders', async function(assert) {
await render(hbs`
<ShadowDom id='internal'>
<ShadowDom id='internal' @mode='open'>
<div class='block'>template block text</div>
</ShadowDom>
`);

assert.dom('.block', find('#internal').shadowRoot).hasText('template block text');
});

test('it can be closed', async function(assert) {
await render(hbs`
<ShadowDom id='internal' @mode='closed'>
<div class='block'>template block text</div>
</ShadowDom>
`);

assert.dom('.block', find('#internal').shadowRoot).doesNotExist();
});
});

0 comments on commit 3a25ed8

Please sign in to comment.