Skip to content
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

feat: bodyElement can be passed as an argument #131

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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>
Loading