Skip to content

Commit 712cf4f

Browse files
authored
Issue #75: added getPopupContainer (#76)
1 parent 3666e66 commit 712cf4f

File tree

9 files changed

+32
-0
lines changed

9 files changed

+32
-0
lines changed

src/Cron.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default function Cron(props: CronProps) {
6161
],
6262
allowClear,
6363
dropdownsConfig,
64+
getPopupContainer,
6465
} = props
6566
const internalValueRef = useRef<string>(value)
6667
const defaultPeriodRef = useRef<PeriodType>(defaultPeriod)
@@ -292,6 +293,7 @@ export default function Cron(props: CronProps) {
292293
shortcuts={shortcuts}
293294
allowedPeriods={allowedPeriods}
294295
allowClear={dropdownsConfig?.period?.allowClear ?? allowClear}
296+
getPopupContainer={getPopupContainer}
295297
/>
296298
)}
297299

@@ -319,6 +321,7 @@ export default function Cron(props: CronProps) {
319321
mode={dropdownsConfig?.months?.mode ?? mode}
320322
allowClear={dropdownsConfig?.months?.allowClear ?? allowClear}
321323
filterOption={dropdownsConfig?.months?.filterOption}
324+
getPopupContainer={getPopupContainer}
322325
/>
323326
)}
324327

@@ -345,6 +348,7 @@ export default function Cron(props: CronProps) {
345348
dropdownsConfig?.['month-days']?.allowClear ?? allowClear
346349
}
347350
filterOption={dropdownsConfig?.['month-days']?.filterOption}
351+
getPopupContainer={getPopupContainer}
348352
/>
349353
)}
350354

@@ -374,6 +378,7 @@ export default function Cron(props: CronProps) {
374378
dropdownsConfig?.['week-days']?.allowClear ?? allowClear
375379
}
376380
filterOption={dropdownsConfig?.['week-days']?.filterOption}
381+
getPopupContainer={getPopupContainer}
377382
/>
378383
)}
379384

@@ -400,6 +405,7 @@ export default function Cron(props: CronProps) {
400405
mode={dropdownsConfig?.hours?.mode ?? mode}
401406
allowClear={dropdownsConfig?.hours?.allowClear ?? allowClear}
402407
filterOption={dropdownsConfig?.hours?.filterOption}
408+
getPopupContainer={getPopupContainer}
403409
/>
404410
)}
405411

@@ -426,6 +432,7 @@ export default function Cron(props: CronProps) {
426432
dropdownsConfig?.minutes?.allowClear ?? allowClear
427433
}
428434
filterOption={dropdownsConfig?.minutes?.filterOption}
435+
getPopupContainer={getPopupContainer}
429436
/>
430437
)}
431438

src/components/CustomSelect.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default function CustomSelect(props: CustomSelectProps) {
2525
mode,
2626
allowClear,
2727
filterOption = () => true,
28+
getPopupContainer,
2829
...otherProps
2930
} = props
3031

@@ -284,6 +285,7 @@ export default function CustomSelect(props: CustomSelectProps) {
284285
: undefined
285286
}
286287
data-testid={`custom-select-${unit.type}`}
288+
getPopupContainer={getPopupContainer}
287289
{...otherProps}
288290
/>
289291
)

src/fields/Hours.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function Hours(props: HoursProps) {
2121
mode,
2222
allowClear,
2323
filterOption,
24+
getPopupContainer,
2425
} = props
2526
const internalClassName = useMemo(
2627
() =>
@@ -55,6 +56,7 @@ export default function Hours(props: HoursProps) {
5556
mode={mode}
5657
allowClear={allowClear}
5758
filterOption={filterOption}
59+
getPopupContainer={getPopupContainer}
5860
/>
5961
</div>
6062
)

src/fields/Minutes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function Minutes(props: MinutesProps) {
2121
mode,
2222
allowClear,
2323
filterOption,
24+
getPopupContainer,
2425
} = props
2526
const internalClassName = useMemo(
2627
() =>
@@ -69,6 +70,7 @@ export default function Minutes(props: MinutesProps) {
6970
mode={mode}
7071
allowClear={allowClear}
7172
filterOption={filterOption}
73+
getPopupContainer={getPopupContainer}
7274
/>
7375

7476
{period === 'hour' && locale.suffixMinutesForHourPeriod !== '' && (

src/fields/MonthDays.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function MonthDays(props: MonthDaysProps) {
2121
mode,
2222
allowClear,
2323
filterOption,
24+
getPopupContainer,
2425
} = props
2526
const noWeekDays = !weekDays || weekDays.length === 0
2627

@@ -77,6 +78,7 @@ export default function MonthDays(props: MonthDaysProps) {
7778
mode={mode}
7879
allowClear={allowClear}
7980
filterOption={filterOption}
81+
getPopupContainer={getPopupContainer}
8082
/>
8183
</div>
8284
) : null

src/fields/Months.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function Months(props: MonthsProps) {
2020
mode,
2121
allowClear,
2222
filterOption,
23+
getPopupContainer,
2324
} = props
2425
const optionsList = locale.months || DEFAULT_LOCALE_EN.months
2526

@@ -62,6 +63,7 @@ export default function Months(props: MonthsProps) {
6263
mode={mode}
6364
allowClear={allowClear}
6465
filterOption={filterOption}
66+
getPopupContainer={getPopupContainer}
6567
/>
6668
</div>
6769
)

src/fields/Period.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default function Period(props: PeriodProps) {
1717
shortcuts,
1818
allowedPeriods,
1919
allowClear,
20+
getPopupContainer,
2021
} = props
2122
const options: BaseOptionType[] = []
2223

@@ -133,6 +134,7 @@ export default function Period(props: PeriodProps) {
133134
open={readOnly ? false : undefined}
134135
data-testid='select-period'
135136
allowClear={allowClear}
137+
getPopupContainer={getPopupContainer}
136138
/>
137139
</div>
138140
)

src/fields/WeekDays.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function WeekDays(props: WeekDaysProps) {
2121
mode,
2222
allowClear,
2323
filterOption,
24+
getPopupContainer,
2425
} = props
2526
const optionsList = locale.weekDays || DEFAULT_LOCALE_EN.weekDays
2627
const noMonthDays = period === 'week' || !monthDays || monthDays.length === 0
@@ -101,6 +102,7 @@ export default function WeekDays(props: WeekDaysProps) {
101102
mode={mode}
102103
allowClear={allowClear}
103104
filterOption={filterOption}
105+
getPopupContainer={getPopupContainer}
104106
/>
105107
</div>
106108
) : null

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ export interface CronProps {
224224
* Default './src/locale.ts'
225225
*/
226226
locale?: Locale
227+
228+
/*
229+
* Define the container for the dropdowns.
230+
* By default, the dropdowns will be rendered in the body.
231+
* This is useful when you want to render the dropdowns in a specific
232+
* container, for example, when using a modal or a specific layout.
233+
*/
234+
getPopupContainer?: () => HTMLElement
227235
}
228236
export interface Locale {
229237
everyText?: string
@@ -343,6 +351,7 @@ export interface FieldProps {
343351
mode: Mode
344352
allowClear?: boolean
345353
filterOption?: FilterOption
354+
getPopupContainer?: () => HTMLElement
346355
}
347356
export interface PeriodProps
348357
extends Omit<
@@ -358,6 +367,7 @@ export interface PeriodProps
358367
setValue: SetValuePeriod
359368
shortcuts: Shortcuts
360369
allowedPeriods: PeriodType[]
370+
getPopupContainer?: () => HTMLElement
361371
}
362372
export interface MonthsProps extends FieldProps {
363373
humanizeLabels: boolean
@@ -412,6 +422,7 @@ export interface CustomSelectProps
412422
periodicityOnDoubleClick: boolean
413423
mode: Mode
414424
filterOption?: FilterOption
425+
getPopupContainer?: () => HTMLElement
415426
}
416427
export type SetValueNumbersOrUndefined = Dispatch<
417428
SetStateAction<number[] | undefined>

0 commit comments

Comments
 (0)