Skip to content

Commit 2330f72

Browse files
chore(DatePicker): updated popover to append inline
1 parent e105747 commit 2330f72

File tree

4 files changed

+788
-6
lines changed

4 files changed

+788
-6
lines changed

packages/react-core/src/components/DatePicker/DatePicker.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface DatePickerProps
2222
* menuAppendTo={() => document.body};
2323
* menuAppendTo={document.getElementById('target')}
2424
*/
25-
appendTo?: HTMLElement | ((ref?: HTMLElement) => HTMLElement) | 'parent';
25+
appendTo?: HTMLElement | ((ref?: HTMLElement) => HTMLElement) | 'inline';
2626
/** Accessible label for the date picker. */
2727
'aria-label'?: string;
2828
/** Accessible label for the button to open the date picker. */
@@ -95,7 +95,7 @@ const DatePickerBase = (
9595
onBlur = (): any => undefined,
9696
invalidFormatText = 'Invalid date',
9797
helperText,
98-
appendTo = 'parent',
98+
appendTo = 'inline',
9999
popoverProps,
100100
monthFormat,
101101
weekdayFormat,
@@ -120,6 +120,7 @@ const DatePickerBase = (
120120
const style = { '--pf-c-date-picker__input--c-form-control--width-chars': widthChars, ...styleProps };
121121
const buttonRef = React.useRef<HTMLButtonElement>();
122122
const datePickerWrapperRef = React.useRef<HTMLDivElement>();
123+
const inputGroupRef = React.useRef<HTMLDivElement>();
123124

124125
React.useEffect(() => {
125126
setValue(valueProp);
@@ -197,8 +198,7 @@ const DatePickerBase = (
197198
[setPopoverOpen, popoverOpen, selectOpen]
198199
);
199200

200-
const getParentElement = () =>
201-
datePickerWrapperRef && datePickerWrapperRef.current ? datePickerWrapperRef.current : null;
201+
const getInlineParentElement = () => inputGroupRef?.current;
202202

203203
return (
204204
<div className={css(styles.datePicker, className)} ref={datePickerWrapperRef} style={style} {...props}>
@@ -243,11 +243,11 @@ const DatePickerBase = (
243243
withFocusTrap
244244
hasNoPadding
245245
hasAutoWidth
246-
appendTo={appendTo === 'parent' ? getParentElement() : appendTo}
246+
appendTo={appendTo === 'inline' ? getInlineParentElement() : appendTo}
247247
{...popoverProps}
248248
>
249249
<div className={styles.datePickerInput}>
250-
<InputGroup>
250+
<InputGroup innerRef={inputGroupRef}>
251251
<TextInput
252252
isDisabled={isDisabled}
253253
aria-label={ariaLabel}

packages/react-core/src/components/DatePicker/__tests__/DatePicker.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { DatePicker } from '../DatePicker';
33
import React from 'react';
44
import userEvent from '@testing-library/user-event';
55

6+
jest.mock('../../../helpers/util.ts')
7+
68
test('disabled date picker', () => {
79
const { asFragment } = render(<DatePicker value="2020-11-20" isDisabled aria-label="disabled date picker" />);
810
expect(asFragment()).toMatchSnapshot();
@@ -48,3 +50,14 @@ test('Error state can be cleared from outside', async () => {
4850

4951
expect(screen.getByRole('textbox')).not.toBeInvalid();
5052
});
53+
54+
test('With popover opened', async () => {
55+
const user = userEvent.setup();
56+
57+
const { asFragment } = render(<DatePicker />);
58+
59+
await user.click(screen.getByRole('button', { name: 'Toggle date picker' }));
60+
await screen.findByRole('button', { name: 'Previous month' });
61+
62+
expect(asFragment()).toMatchSnapshot();
63+
})

0 commit comments

Comments
 (0)