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

fix: add support for th elements (#276) #650

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/popper/src/utils/getOffsetParent.js
Expand Up @@ -27,10 +27,10 @@ export default function getOffsetParent(element) {
return element ? element.ownerDocument.documentElement : document.documentElement;
}

// .offsetParent will return the closest TD or TABLE in case
// .offsetParent will return the closest TH, TD or TABLE in case
// no offsetParent is present, I hate this job...
if (
['TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 &&
['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 &&
getStyleComputedProperty(offsetParent, 'position') === 'static'
) {
return getOffsetParent(offsetParent);
Expand Down
50 changes: 49 additions & 1 deletion packages/popper/tests/functional/core.js
Expand Up @@ -1720,7 +1720,7 @@ const arrowSize = 5;
);

// test for #276
it('works inside tables', done => {
it('works inside table td elements', done => {
jasmineWrapper.innerHTML = `
<style>
table {
Expand Down Expand Up @@ -1767,6 +1767,54 @@ const arrowSize = 5;
});
});

// test for #276
it('works inside table th elements', done => {
jasmineWrapper.innerHTML = `
<style>
table {
margin-top: 50px;
}
#reference {
background: orange;
width: 50px;
height: 50px;
}
#popper {
background: green;
width: 50px;
height: 50px;
}
</style>
<table>
<tbody>
<tr>
<th>
<div id="reference">
ref
</div>
<div id="popper">
pop
</div>
</th>
</tr>
</tbody>
</table>
`;

const reference = document.getElementById('reference');
const popper = document.getElementById('popper');

new Popper(reference, popper, {
placement: 'bottom',
onCreate(data) {
expect(getRect(reference).bottom).toBeApprox(getRect(popper).top);
expect(getRect(reference).left).toBeApprox(getRect(popper).left);
data.instance.destroy();
done();
},
});
});

// test for #453
// When the reference is inside a scrollParent, it should be used as the
// source for choosing the scrollParent rather than the popper.
Expand Down