Skip to content

Commit 032cbe7

Browse files
Conrad Chanmergify[bot]
andauthored
fix(popupreply): Adjust positioning for IE11 (#609)
* fix(popupreply): Adjust positioning for IE11 * chore: address pr comments * chore: remove unneeded dev dependency Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 10702e8 commit 032cbe7

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
},
2222
restoreMocks: true,
2323
roots: ['src'],
24-
setupFiles: ['jest-canvas-mock'],
24+
setupFiles: ['jest-canvas-mock', '<rootDir>/test/jest/envWindow.js'],
2525
setupFilesAfterEnv: ['<rootDir>/scripts/jest/enzyme-adapter.js'],
2626
snapshotSerializers: ['enzyme-to-json/serializer'],
2727
testEnvironment: 'jest-environment-jsdom-sixteen',

src/components/Popups/PopupBase.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
@include ba-PopupArrow(12px, $popup-content-bg, $popup-content-bg, $popup-footer-bg, $popup-content-bg, $popup-border-color);
1212

1313
z-index: 1; // Make sure popup is showing above Preview controls and left/right arrows
14+
}
15+
16+
// The following media query is specific to IE10+
17+
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
18+
.ba-Popup {
19+
z-index: 0; // Changing z-index causes page to flicker in IE11
20+
}
1421

15-
// Changing z-index causes page to flicker in IE11
16-
// The following media query is specific to IE10+
17-
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
18-
z-index: 0;
22+
.ba-ItemList {
23+
// stylelint-disable-next-line declaration-no-important
24+
max-height: 140px !important; // Prevent list overflow onto subsequent pages in IE11
1925
}
2026
}
2127

src/components/Popups/PopupReply.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export type Props = {
1818
value?: string;
1919
};
2020

21+
const isIE = (): boolean => {
22+
const { userAgent } = navigator;
23+
return userAgent.indexOf('Trident/') > 0;
24+
};
25+
2126
export const options: Partial<Popper.Options> = {
2227
modifiers: [
2328
{
@@ -64,11 +69,20 @@ export default function PopupReply({
6469
...rest
6570
}: Props): JSX.Element {
6671
const popupRef = React.useRef<PopupBase>(null);
72+
const popupOptions = React.useRef<Partial<Popper.Options> | null>(null);
6773
const rotation = ReactRedux.useSelector(getRotation);
6874
const prevRotation = usePrevious(rotation);
6975
const scale = ReactRedux.useSelector(getScale);
7076
const prevScale = usePrevious(scale);
7177

78+
// Keep the options reference the same between renders
79+
if (!popupOptions.current) {
80+
popupOptions.current = {
81+
...options,
82+
placement: isIE() ? 'top' : 'bottom',
83+
};
84+
}
85+
7286
React.useEffect(() => {
7387
const { current: popup } = popupRef;
7488

@@ -78,7 +92,7 @@ export default function PopupReply({
7892
}, [popupRef, rotation, scale]); // eslint-disable-line react-hooks/exhaustive-deps
7993

8094
return (
81-
<PopupBase ref={popupRef} data-resin-component="popupReply" options={options} {...rest}>
95+
<PopupBase ref={popupRef} data-resin-component="popupReply" options={popupOptions.current} {...rest}>
8296
<ReplyForm
8397
isPending={isPending}
8498
onCancel={onCancel}

src/components/Popups/__tests__/PopupReply-test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,37 @@ describe('PopupReply', () => {
5252
expect(wrapper.exists(PopupBase)).toBe(true);
5353
expect(wrapper.exists(ReplyForm)).toBe(true);
5454
});
55+
56+
test('should maintain referential integrity of the PopupBase options object across renders', () => {
57+
const wrapper = getWrapper();
58+
59+
const popupOptions = wrapper.find(PopupBase).prop('options');
60+
61+
expect(wrapper.exists(PopupBase)).toBe(true);
62+
expect(wrapper.find(ReplyForm).prop('value')).toBe('');
63+
64+
wrapper.setProps({ value: '1' });
65+
66+
expect(wrapper.find(PopupBase).prop('options')).toStrictEqual(popupOptions);
67+
expect(wrapper.find(ReplyForm).prop('value')).toBe('1');
68+
});
69+
});
70+
71+
describe('Popup options', () => {
72+
test.each`
73+
userAgent | expectedPlacement
74+
${'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'} | ${'top'}
75+
${'Other'} | ${'bottom'}
76+
`(
77+
'should set placement option as $expectedPlacement based on userAgent=$userAgent',
78+
({ userAgent, expectedPlacement }) => {
79+
global.window.navigator.userAgent = userAgent;
80+
81+
const wrapper = getWrapper();
82+
83+
expect(window.navigator.userAgent).toEqual(userAgent);
84+
expect(wrapper.find(PopupBase).prop('options').placement).toBe(expectedPlacement);
85+
},
86+
);
5587
});
5688
});

test/jest/envWindow.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Object.defineProperty(
2+
window.navigator,
3+
'userAgent',
4+
(value => ({
5+
get() {
6+
return value;
7+
},
8+
set(v) {
9+
value = v;
10+
},
11+
}))(window.navigator.userAgent),
12+
);

0 commit comments

Comments
 (0)