Skip to content

Commit 2efe6a5

Browse files
authored
Merge pull request #847 from topcoder-platform/MP-305_modals-dropdowns
MP-305 - use popper & portals -> dev
2 parents c99993d + fc03016 commit 2efe6a5

File tree

10 files changed

+90
-67
lines changed

10 files changed

+90
-67
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"@datadog/browser-logs": "^4.21.2",
2525
"@heroicons/react": "^1.0.6",
26+
"@popperjs/core": "^2.11.8",
2627
"@sprig-technologies/sprig-browser": "^2.20.1",
2728
"@storybook/addon-actions": "^7.0.5",
2829
"@storybook/react": "^7.0.5",
@@ -83,6 +84,7 @@
8384
"react-helmet": "^6.1.0",
8485
"react-html-parser": "^2.0.2",
8586
"react-markdown": "8.0.6",
87+
"react-popper": "^2.3.0",
8688
"react-redux": "^8.0.4",
8789
"react-redux-toastr": "^7.6.10",
8890
"react-responsive": "^9.0.0-beta.5",

src/apps/profiles/src/member-profile/languages/ModifyLanguagesModal/ModifyLanguagesModal.module.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,3 @@
5050
}
5151
}
5252
}
53-
54-
.langModal {
55-
@include gtemd {
56-
overflow: visible !important;
57-
}
58-
}
59-
60-
.langModalBody {
61-
overflow: visible !important;
62-
}

src/apps/profiles/src/member-profile/local-info/ModifyLocationModal/ModifyLocationModal.module.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,3 @@
1717
margin-bottom: $sp-4;
1818
}
1919
}
20-
21-
.localModal {
22-
@include gtemd {
23-
overflow: visible !important;
24-
}
25-
}
26-
27-
.localModalBody {
28-
overflow: visible !important;
29-
}

src/apps/profiles/src/member-profile/skills/ModifySkillsModal/ModifySkillsModal.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828

2929
.skillsModalBody {
3030
overflow: visible !important;
31-
}
31+
}

src/apps/profiles/src/member-profile/work-expirence/ModifyWorkExpirenceModal/ModifyWorkExpirenceModal.module.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
align-items: center;
2929
margin-left: $sp-15;
3030

31+
@include ltemd {
32+
margin-left: $sp-4;
33+
}
34+
3135
:global(button) {
3236
padding: $sp-2;
3337
color: $turq-160;
@@ -83,4 +87,4 @@
8387
display: flex;
8488
justify-content: space-between;
8589
width: 100%;
86-
}
90+
}

src/libs/ui/lib/components/form/form-groups/form-input/input-date-picker/InputDatePicker.module.scss

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@import '@libs/ui/styles/includes';
22

3-
.container {
3+
:global(#react-date-portal) {
4+
position: relative;
5+
z-index: 10001;
46
:global(.react-datepicker__header) {
57
background-color: $tc-white;
68
border-bottom: none;
@@ -30,34 +32,36 @@
3032
color: $tc-white;
3133
border-radius: 50%;
3234
}
35+
}
3336

34-
.headerWrap {
35-
display: flex;
36-
justify-content: space-between;
37-
padding: $sp-2 0;
38-
border-bottom: 2px solid $black-5;
37+
.headerWrap {
38+
display: flex;
39+
justify-content: space-between;
40+
padding: $sp-2 0;
41+
border-bottom: 2px solid $black-5;
3942

40-
button {
41-
svg {
42-
width: 27px;
43-
height: 27px;
44-
}
43+
button {
44+
svg {
45+
width: 27px;
46+
height: 27px;
4547
}
48+
}
4649

47-
select {
48-
border: none;
49-
background-color: transparent;
50-
margin: auto;
51-
-webkit-appearance: menulist;
52-
appearance: menulist;
50+
select {
51+
border: none;
52+
background-color: transparent;
53+
margin: auto;
54+
-webkit-appearance: menulist;
55+
appearance: menulist;
5356

54-
option:hover {
55-
background-color: $turq-160;
56-
color: $tc-white;
57-
}
57+
option:hover {
58+
background-color: $turq-160;
59+
color: $tc-white;
5860
}
5961
}
62+
}
6063

64+
.container {
6165
input {
6266
border: none;
6367
pointer-events: none;
@@ -74,4 +78,4 @@
7478
text-transform: none;
7579
}
7680
}
77-
}
81+
}

src/libs/ui/lib/components/form/form-groups/form-input/input-date-picker/InputDatePicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ const InputDatePicker: FC<InputDatePickerProps> = (props: InputDatePickerProps)
130130
maxTime={props.maxTime}
131131
showYearPicker={props.showYearPicker}
132132
dateFormat={props.dateFormat}
133+
popperPlacement='bottom'
134+
portalId='react-date-portal'
133135
/>
134136
</InputWrapper>
135137
)

src/libs/ui/lib/components/form/form-groups/form-input/input-select/InputSelect.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
left: 0;
2424
width: 100%;
2525
&:not(:empty) {
26-
z-index: 9;
26+
z-index: 1001;
2727
}
2828
}
2929

src/libs/ui/lib/components/form/form-groups/form-input/input-select/InputSelect.tsx

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import {
1111
useRef,
1212
useState,
1313
} from 'react'
14+
import { usePopper } from 'react-popper'
1415
import classNames from 'classnames'
1516

17+
import { beforeWrite } from '@popperjs/core/lib'
1618
import { useClickOutside } from '~/libs/shared/lib/hooks'
1719

1820
import { IconOutline } from '../../../../svgs'
1921
import { InputWrapper } from '../input-wrapper'
22+
import { Portal } from '../../../../portal'
2023

2124
import styles from './InputSelect.module.scss'
2225

@@ -40,12 +43,33 @@ interface InputSelectProps {
4043
readonly value?: string
4144
}
4245

46+
const sameWidthModifier = {
47+
effect: ({ state }: any) => {
48+
state.elements.popper.style.width = `${state.elements.reference.offsetWidth}px`
49+
},
50+
enabled: true,
51+
fn: ({ state }: any) => {
52+
state.styles.popper.width = `${state.rects.reference.width}px`
53+
return state
54+
},
55+
name: 'sameWidth',
56+
phase: beforeWrite,
57+
requires: ['computeStyles'],
58+
}
59+
const modifiers = [sameWidthModifier]
60+
4361
const InputSelect: FC<InputSelectProps> = (props: InputSelectProps) => {
4462
const triggerRef: MutableRefObject<any> = useRef(undefined)
63+
const popperRef: MutableRefObject<any> = useRef(undefined)
4564
const buttonRef: MutableRefObject<HTMLButtonElement | null> = useRef(null)
4665
const [menuIsVisible, setMenuIsVisible]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
4766
const [isFocus, setIsFocus]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
4867

68+
const popper = usePopper(triggerRef.current?.firstChild, popperRef.current, {
69+
modifiers,
70+
strategy: 'absolute',
71+
})
72+
4973
const selectedOption: InputSelectOption | undefined = props.options.find(option => option.value === props.value)
5074

5175
const label: (option: InputSelectOption) => ReactNode = (option?: InputSelectOption) => (
@@ -125,27 +149,34 @@ const InputSelect: FC<InputSelectProps> = (props: InputSelectProps) => {
125149
</span>
126150
</button>
127151

128-
<div className={styles['menu-wrap']}>
129-
{menuIsVisible && (
130-
<div className={styles['select-menu']}>
131-
{props.options.map(option => (
132-
<div
133-
className={
134-
classNames(
135-
styles['select-option'],
136-
'body-main',
137-
selectedOption === option && 'selected',
138-
)
139-
}
140-
onClick={select(option)}
141-
key={option.value}
142-
>
143-
{label(option)}
144-
</div>
145-
))}
146-
</div>
147-
)}
148-
</div>
152+
<Portal>
153+
<div
154+
className={styles['menu-wrap']}
155+
ref={popperRef}
156+
style={popper.styles.popper}
157+
{...popper.attributes.popper}
158+
>
159+
{menuIsVisible && (
160+
<div className={styles['select-menu']}>
161+
{props.options.map(option => (
162+
<div
163+
className={
164+
classNames(
165+
styles['select-option'],
166+
'body-main',
167+
selectedOption === option && 'selected',
168+
)
169+
}
170+
onClick={select(option)}
171+
key={option.value}
172+
>
173+
{label(option)}
174+
</div>
175+
))}
176+
</div>
177+
)}
178+
</div>
179+
</Portal>
149180

150181
</InputWrapper>
151182
)

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2721,7 +2721,7 @@
27212721
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
27222722
integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==
27232723

2724-
"@popperjs/core@^2.9.2":
2724+
"@popperjs/core@^2.11.8", "@popperjs/core@^2.9.2":
27252725
version "2.11.8"
27262726
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
27272727
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==

0 commit comments

Comments
 (0)