Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(DatePicker): updated popover to append inline #8636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/react-core/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { isValidDate } from '../../helpers/datetimeUtils';
export interface DatePickerProps
extends CalendarFormat,
Omit<React.HTMLProps<HTMLInputElement>, 'onChange' | 'onFocus' | 'onBlur' | 'disabled' | 'ref'> {
/** The container to append the menu to. Defaults to 'parent'.
/** The container to append the menu to. Defaults to 'inline'.
* If your menu is being cut off you can append it to an element higher up the DOM tree.
* Some examples:
* menuAppendTo={() => document.body};
* menuAppendTo={document.getElementById('target')}
*/
appendTo?: HTMLElement | ((ref?: HTMLElement) => HTMLElement) | 'parent';
appendTo?: HTMLElement | ((ref?: HTMLElement) => HTMLElement) | 'inline';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to change the jsdoc default as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

/** Accessible label for the date picker. */
'aria-label'?: string;
/** Accessible label for the button to open the date picker. */
Expand Down Expand Up @@ -95,7 +95,7 @@ const DatePickerBase = (
onBlur = (): any => undefined,
invalidFormatText = 'Invalid date',
helperText,
appendTo = 'parent',
appendTo = 'inline',
popoverProps,
monthFormat,
weekdayFormat,
Expand Down Expand Up @@ -197,9 +197,6 @@ const DatePickerBase = (
[setPopoverOpen, popoverOpen, selectOpen]
);

const getParentElement = () =>
datePickerWrapperRef && datePickerWrapperRef.current ? datePickerWrapperRef.current : null;

return (
<div className={css(styles.datePicker, className)} ref={datePickerWrapperRef} style={style} {...props}>
<Popover
Expand Down Expand Up @@ -243,7 +240,7 @@ const DatePickerBase = (
withFocusTrap
hasNoPadding
hasAutoWidth
appendTo={appendTo === 'parent' ? getParentElement() : appendTo}
appendTo={appendTo}
{...popoverProps}
>
<div className={styles.datePickerInput}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { DatePicker } from '../DatePicker';
import React from 'react';
import userEvent from '@testing-library/user-event';

jest.mock('../../../helpers/util.ts')

test('disabled date picker', () => {
const { asFragment } = render(<DatePicker value="2020-11-20" isDisabled aria-label="disabled date picker" />);
expect(asFragment()).toMatchSnapshot();
Expand Down Expand Up @@ -48,3 +50,14 @@ test('Error state can be cleared from outside', async () => {

expect(screen.getByRole('textbox')).not.toBeInvalid();
});

test('With popover opened', async () => {
const user = userEvent.setup();

const { asFragment } = render(<DatePicker />);

await user.click(screen.getByRole('button', { name: 'Toggle date picker' }));
await screen.findByRole('button', { name: 'Previous month' });

expect(asFragment()).toMatchSnapshot();
})