Skip to content

Commit

Permalink
feat: bodyElement can be passed as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
cyril-sf committed Nov 8, 2024
1 parent 7215dc7 commit 4d0d958
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon/components/ember-tether.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default class EmberTetherComponent extends Component {
}

get bodyElement() {
if (this.args.bodyElement) {
return document.getElementById(this.args.bodyElement);
}

let config = this.emberTetherConfig;
if (config && config.bodyElementId) {
return document.getElementById(config.bodyElementId);
Expand Down
24 changes: 24 additions & 0 deletions tests/acceptance/tether-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,25 @@ module('Acceptance | tether test', function (hooks) {
);
};

assert.parentHasId = function (thingSelector, parentId) {
let thing = document.querySelector(thingSelector);
let parent = thing.parentElement;
assert.equal(
parent.id,
parentId,
`${thingSelector}'s parent has id ${parentId}`,
);
};

test('tethering a thing to a target', async function (assert) {
await visit('/');

assert.topAligned('.tethered-thing', '#tether-target-1');
assert.rightOf('.tethered-thing', '#tether-target-1');
assert.topAligned('.another-tethered-thing', '#tether-target-3');
assert.leftOf('.another-tethered-thing', '#tether-target-3');

assert.parentHasId('.tethered-thing', 'ember-testing');
});

test('tethering to an Ember Component', async function (assert) {
Expand Down Expand Up @@ -150,4 +162,16 @@ module('Acceptance | tether test', function (hooks) {
);
});
});

test('bodyElement', async function (assert) {
await visit('/');

assert.topAligned(
'.a-tethered-thing-with-body-element',
'#tether-target-8',
);
assert.rightOf('.a-tethered-thing-with-body-element', '#tether-target-8');

assert.parentHasId('.a-tethered-thing-with-body-element', 'body-element');
});
});
13 changes: 13 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<div id="tether-target-5" class="tether-target">5</div>
<div id="tether-target-6" class="tether-target">6</div>
<div id="tether-target-7" class="tether-target">7</div>
<div id="tether-target-8" class="tether-target">8</div>

<div id="body-element"></div>

<EmberTether
@target={{this.exampleTargetSelector}}
Expand Down Expand Up @@ -120,4 +123,14 @@
A tethered thing with aria attributes
</EmberTether>

<EmberTether
@bodyElement="body-element"
@target="#tether-target-8"
@targetAttachment="top right"
@attachment="top left"
class="a-tethered-thing-with-body-element"
>
Another tethered thing with bodyElement
</EmberTether>

</div>

0 comments on commit 4d0d958

Please sign in to comment.