-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Modal): support IE11, fix scrolling glitches (#3679)
* fix(Modal): support IE11, fix scrolling glitches * fix UT * add missing UT for StepContent * add missing UT for NodeRegistry * add missing UT for GridColumn * add missing UT for PortalInner * add missing UT for getLegacyStyles * add missing UT for canFit
- Loading branch information
1 parent
087593c
commit c884fa9
Showing
9 changed files
with
155 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// https://github.com/Semantic-Org/Semantic-UI/blob/2.4.1/src/definitions/modules/modal.js#L956 | ||
const OFFSET = 0 | ||
// https://github.com/Semantic-Org/Semantic-UI/blob/2.4.1/src/definitions/modules/modal.js#L990 | ||
const PADDING = 50 | ||
|
||
/** | ||
* Ensures that modal can fit viewport without scroll. | ||
* | ||
* @param modalRect {DOMRect} | ||
* | ||
* @see https://github.com/Semantic-Org/Semantic-UI/blob/2.4.1/src/definitions/modules/modal.js#L608 | ||
*/ | ||
export const canFit = (modalRect) => { | ||
// original: scrollHeight = $module.prop('scrollHeight'), | ||
// is replaced by .height because scrollHeight provides integer which produces glitches | ||
// https://github.com/Semantic-Org/Semantic-UI-React/issues/2221 | ||
const scrollHeight = modalRect.height + OFFSET | ||
// $module.outerHeight() + settings.offset | ||
const height = modalRect.height + OFFSET | ||
|
||
// original: $(window).height() | ||
const contextHeight = window.innerHeight | ||
const verticalCenter = contextHeight / 2 | ||
const topOffset = -(height / 2) | ||
|
||
// padding with edge of page | ||
const paddingHeight = PADDING | ||
const startPosition = verticalCenter + topOffset // 0 | ||
|
||
// original: scrollHeight > height | ||
// ? startPosition + scrollHeight + paddingHeight < contextHeight | ||
// : height + paddingHeight * 2 < contextHeight | ||
return startPosition + scrollHeight + paddingHeight < contextHeight | ||
} | ||
|
||
/** | ||
* Creates legacy styles for IE11. | ||
* | ||
* @param isFitted {Boolean} | ||
* @param centered {Boolean} | ||
* @param modalRect {DOMRect} | ||
* | ||
* @see https://github.com/Semantic-Org/Semantic-UI/blob/2.4.1/src/definitions/modules/modal.js#L718 | ||
*/ | ||
export const getLegacyStyles = (isFitted, centered, modalRect) => { | ||
const marginTop = centered && isFitted ? -(modalRect.height / 2) : 0 | ||
const marginLeft = -(modalRect.width / 2) | ||
|
||
return { marginLeft, marginTop } | ||
} | ||
|
||
// https://github.com/Semantic-Org/Semantic-UI/blob/2.4.1/src/definitions/modules/modal.js#L631 | ||
/* istanbul ignore next */ | ||
export const isLegacy = () => !window.ActiveXObject && 'ActiveXObject' in window |
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
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,25 @@ | ||
import { canFit } from 'src/modules/Modal/utils' | ||
|
||
describe('canFit', () => { | ||
const innerHeight = window.innerHeight | ||
|
||
before(() => { | ||
window.innerHeight = 1000 | ||
}) | ||
|
||
after(() => { | ||
window.innerHeight = innerHeight | ||
}) | ||
|
||
it('computes proper result', () => { | ||
;[ | ||
// { rect: { height: 1000 }, fit: false }, | ||
// { rect: { height: 950 }, fit: false }, | ||
{ rect: { height: 900 }, fit: false }, | ||
{ rect: { height: 850 }, fit: true }, | ||
{ rect: { height: 800 }, fit: true }, | ||
].forEach((check) => { | ||
canFit(check.rect).should.be.equal(check.fit) | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
import { getLegacyStyles } from 'src/modules/Modal/utils' | ||
|
||
const rectMock = { | ||
height: 200, | ||
width: 100, | ||
} | ||
|
||
describe('getLegacyStyles', () => { | ||
it('computes proper result', () => { | ||
;[ | ||
{ centered: true, fitted: false, result: { marginTop: 0, marginLeft: -50 } }, | ||
{ centered: false, fitted: true, result: { marginTop: 0, marginLeft: -50 } }, | ||
{ centered: true, fitted: true, result: { marginTop: -100, marginLeft: -50 } }, | ||
].forEach(({ centered, fitted, result }) => { | ||
getLegacyStyles(centered, fitted, rectMock).should.be.deep.equal(result) | ||
}) | ||
}) | ||
}) |