This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
fix(Popup): allow to 'detach' from trigger and RTL adjustments #612
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
31111c4
introduce offset prop
kuzhelov-ms ccf678c
correct description of supported values
kuzhelov-ms 557aeae
Merge branch 'master' into feat/add-offset-prop-to-popup
kuzhelov 47ad701
update changelog
kuzhelov-ms 3508ed8
introduce fix
kuzhelov-ms 1d37789
Merge branch 'master' into fix/popup-offset-values-range
kuzhelov 94e684f
ensure RTL is properly applied to complex offset expressions
kuzhelov-ms 6a1f62b
Merge branch 'fix/popup-offset-values-range' of https://github.com/st…
kuzhelov-ms bf1f8e7
rename method to make logic more expressive
kuzhelov-ms a09af48
add unit tests
kuzhelov-ms 3e7be81
remove unnecessary grid props from offset example
kuzhelov-ms 07878bd
Merge branch 'master' into fix/popup-offset-values-range
kuzhelov 425f289
update changelog
kuzhelov-ms dc6251a
Merge branch 'master' into fix/popup-offset-values-range
kuzhelov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import computePopupPlacement, { Position, Alignment } from 'src/components/Popup/positioningHelper' | ||
import { | ||
getPopupPlacement, | ||
applyRtlToOffset, | ||
Position, | ||
Alignment, | ||
} from 'src/components/Popup/positioningHelper' | ||
import { Placement } from 'popper.js' | ||
|
||
type PositionTestInput = { | ||
|
@@ -16,7 +21,7 @@ describe('Popup', () => { | |
rtl = false, | ||
}: PositionTestInput) => | ||
it(`Popup ${position} position is transformed to ${expectedPlacement} Popper's placement`, () => { | ||
const actualPlacement = computePopupPlacement({ align, position, rtl }) | ||
const actualPlacement = getPopupPlacement({ align, position, rtl }) | ||
expect(actualPlacement).toEqual(expectedPlacement) | ||
}) | ||
|
||
|
@@ -56,4 +61,45 @@ describe('Popup', () => { | |
testPopupPositionInRtl({ position: 'after', align: 'center', expectedPlacement: 'left' }) | ||
testPopupPositionInRtl({ position: 'after', align: 'bottom', expectedPlacement: 'left-end' }) | ||
}) | ||
|
||
describe('Popup offset transformed correctly in RTL', () => { | ||
it("applies transform only for 'above' and 'below' postioning", () => { | ||
const originalOffsetValue = '100%' | ||
|
||
expect(applyRtlToOffset(originalOffsetValue, 'above')).not.toBe(originalOffsetValue) | ||
expect(applyRtlToOffset(originalOffsetValue, 'below')).not.toBe(originalOffsetValue) | ||
|
||
expect(applyRtlToOffset(originalOffsetValue, 'before')).toBe(originalOffsetValue) | ||
expect(applyRtlToOffset(originalOffsetValue, 'after')).toBe(originalOffsetValue) | ||
}) | ||
|
||
const expectOffsetTransformResult = (originalOffset, resultOffset) => { | ||
expect(applyRtlToOffset(originalOffset, 'above')).toBe(resultOffset) | ||
} | ||
|
||
it('flips sign of simple expressions', () => { | ||
expectOffsetTransformResult('100%', '-100%') | ||
expectOffsetTransformResult(' 2000%p ', '-2000%p') | ||
expectOffsetTransformResult('100 ', '-100') | ||
expectOffsetTransformResult(' - 200vh', '200vh') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have intentionally selected this approach for the following reasons:
|
||
}) | ||
|
||
it('flips sign of complex expressions', () => { | ||
expectOffsetTransformResult('100% + 200', '-100% - 200') | ||
expectOffsetTransformResult(' - 2000%p - 400 +800vh ', '2000%p + 400 -800vh') | ||
}) | ||
|
||
it('transforms only horizontal offset value', () => { | ||
const xOffset = '-100%' | ||
const yOffset = '800vh' | ||
|
||
const offsetValue = [xOffset, yOffset].join(',') | ||
const [xOffsetTransformed, yOffsetTransformed] = applyRtlToOffset(offsetValue, 'above').split( | ||
',', | ||
) | ||
|
||
expect(xOffsetTransformed.trim()).not.toBe(xOffset) | ||
expect(yOffsetTransformed.trim()).toBe(yOffset) | ||
}) | ||
}) | ||
}) |
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.
This looks a complicated for me, but we have tests. Possibly, we can to add memoization there.
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.
yes, the tests were introduced exactly for this sake :) not sure about memoization, as all expressions used are of linear complexity - there shouldn't be any significant gain from it.