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: Add specific padding to boundaries (#518) #615
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import getBoundaries from '../../src/utils/getBoundaries'; | ||
import isIE from '../../src/utils/isIE'; | ||
|
||
describe('utils/getBoundaries', () => { | ||
let node; | ||
let spacing; | ||
let scrolling; | ||
let scrollingChild; | ||
let popper; | ||
let scrollingPopper; | ||
|
||
function setCss(element, css) { | ||
for (const key in css) { | ||
if (css.hasOwnProperty(key)) { | ||
element.style[key] = css[key]; | ||
} | ||
} | ||
} | ||
function expectBoundary(result, expected) { | ||
const tolerance = 2; | ||
expect(Math.abs(result.top - expected.top) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.right - expected.right) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.bottom - expected.bottom) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.left - expected.left) <= tolerance).toBeTruthy(); | ||
} | ||
|
||
beforeEach(() => { | ||
node = document.createElement('div'); | ||
spacing = document.createElement('div'); | ||
popper = document.createElement('div'); | ||
scrollingPopper = document.createElement('div'); | ||
|
||
scrolling = document.createElement('div'); | ||
setCss(scrolling, { | ||
top: '150px', | ||
left: '160px', | ||
right: '300px', | ||
bottom: '400px', | ||
height: '150px', | ||
width: '125px', | ||
}); | ||
|
||
scrollingChild = document.createElement('div'); | ||
setCss(scrollingChild, { | ||
overflow: 'scroll', | ||
top: '50px', | ||
left: '60px', | ||
right: '-100px', | ||
bottom: '-200px', | ||
height: '350px', | ||
width: '625px', | ||
position: 'absolute', | ||
transform: 'translate3d(100px, 100px, 0)', | ||
willChange: 'transform', | ||
}); | ||
|
||
document.body.appendChild(node); | ||
node.appendChild(spacing); | ||
node.appendChild(scrolling); | ||
node.appendChild(popper); | ||
scrolling.appendChild(scrollingChild); | ||
scrollingChild.appendChild(scrollingPopper); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(node); | ||
}); | ||
|
||
it('returns a boundary defined by the document element.', () => { | ||
const result = getBoundaries(popper, node, 0, 'window', true); | ||
expectBoundary(result, { | ||
top: 0, | ||
right: window.innerWidth, | ||
bottom: window.innerHeight, | ||
left: 0, | ||
}); | ||
}); | ||
|
||
it('returns a boundary defined by the document element by way of a child reference.', () => { | ||
const result = getBoundaries(popper, spacing, 0, 'scrollParent', true); | ||
expectBoundary(result, { | ||
top: 0, | ||
right: window.innerWidth, | ||
bottom: window.innerHeight, | ||
left: 0, | ||
}); | ||
}); | ||
|
||
it('returns a custom defined boundary within the page.', () => { | ||
const result = getBoundaries(scrollingPopper, scrollingChild, 0, 'scrollParent', false); | ||
expectBoundary(result, { | ||
top: -150, | ||
right: window.innerWidth - 160, | ||
bottom: window.innerHeight - 150, | ||
left: -160, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import getBoundaries from '../../src/utils/getBoundaries'; | ||
|
||
describe('utils/getBoundaries-padding-offset', () => { | ||
let node; | ||
|
||
beforeEach(() => { | ||
node = document.createElement('div'); | ||
document.body.appendChild(node); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(node); | ||
}); | ||
|
||
function expectBoundary(result, expected) { | ||
const tolerance = 2; | ||
expect(Math.abs(result.top - expected.top) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.right - expected.right) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.bottom - expected.bottom) <= tolerance).toBeTruthy(); | ||
expect(Math.abs(result.left - expected.left) <= tolerance).toBeTruthy(); | ||
} | ||
|
||
it('returns a boundary with a single value padding offset.', () => { | ||
const padding = 50; | ||
const result = getBoundaries(null, null, padding, 'viewport', true); | ||
expectBoundary(result, { | ||
top: 50, | ||
right: window.innerWidth - 50, | ||
bottom: window.innerHeight - 50, | ||
left: 50, | ||
}); | ||
}); | ||
|
||
it('returns a boundary with a top and left componentized padding offset.', () => { | ||
const padding = { | ||
top: 50, | ||
left: 100, | ||
}; | ||
const result = getBoundaries(null, null, padding, 'viewport', true); | ||
expectBoundary(result, { | ||
top: 50, | ||
right: window.innerWidth, | ||
bottom: window.innerHeight, | ||
left: 100, | ||
}); | ||
}); | ||
|
||
it('returns a boundary with a bottom and right componentized padding offset.', () => { | ||
const padding = { | ||
bottom: 50, | ||
right: 85, | ||
}; | ||
const result = getBoundaries(null, null, padding, 'viewport', true); | ||
expectBoundary(result, { | ||
top: 0, | ||
right: window.innerWidth - 85, | ||
bottom: window.innerHeight - 50, | ||
left: 0, | ||
}); | ||
}); | ||
|
||
it('returns a boundary with a null padding offset.', () => { | ||
const padding = null; | ||
const result = getBoundaries(null, null, padding, 'viewport', true); | ||
expectBoundary(result, { | ||
top: 0, | ||
right: window.innerWidth, | ||
bottom: window.innerHeight, | ||
left: 0, | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are strings in IE10 such as 0px, so you are doing string concatenation here instead of addition. You end up with 1070px0px0px. Then maxing with that param causes NAN to be returned.