Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import RhMicronsCaretRightIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-right-icon';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/CalendarMonth/calendar-month';
import { useSSRSafeId } from '../../helpers';
import { useSSRSafeId, useOUIAProps, OUIAProps } from '../../helpers';
import { isValidDate } from '../../helpers/datetimeUtils';

export enum Weekday {
Expand Down Expand Up @@ -63,7 +63,7 @@
inlineProps?: CalendarMonthInlineProps;
}

export interface CalendarProps extends CalendarFormat, Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
export interface CalendarProps extends CalendarFormat, Omit<React.HTMLProps<HTMLDivElement>, 'onChange'>, OUIAProps {
/** Additional classes to add to the outer div of the calendar month. */
className?: string;
/** Month/year to base other dates around. */
Expand All @@ -88,6 +88,10 @@
* monthAppendTo={document.getElementById('target')}
*/
monthAppendTo?: HTMLElement | ((ref?: HTMLElement) => HTMLElement) | 'inline';
/** Value to overwrite the randomly generated data-ouia-component-id.*/
ouiaId?: number | string;
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
ouiaSafe?: boolean;
}

const buildCalendar = (year: number, month: number, weekStart: number, validators: ((date: Date) => boolean)[]) => {
Expand Down Expand Up @@ -151,8 +155,11 @@
isDateFocused = false,
inlineProps,
monthAppendTo = 'inline',
ouiaId,
ouiaSafe = true,
...props
}: CalendarProps) => {
const ouiaProps = useOUIAProps(CalendarMonth.displayName, ouiaId, ouiaSafe);
const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
.map((monthNum) => new Date(1990, monthNum))
.map(monthFormat);
Expand Down Expand Up @@ -189,14 +196,14 @@
} else if (!dateProp) {
setFocusedDate(today);
}
}, [dateProp]);

Check warning on line 199 in packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'focusedDate'. Either include it or remove the dependency array

useEffect(() => {
// Calendar month should not be focused on page load
if ((shouldFocus || isDateFocused) && focusedDateValidated && focusRef.current) {
focusRef.current.focus();
}
}, [focusedDate, isDateFocused, focusedDateValidated, focusRef]);

Check warning on line 206 in packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'shouldFocus'. Either include it or remove the dependency array

const onMonthClick = (ev: React.MouseEvent, newDate: Date) => {
setFocusedDate(newDate);
Expand Down Expand Up @@ -293,7 +300,7 @@
const monthFormatted = monthFormat(focusedDate);

const calendarToRender = (
<div className={css(styles.calendarMonth, className)} {...props}>
<div className={css(styles.calendarMonth, className)} {...props} {...ouiaProps}>
<div className={styles.calendarMonthHeader}>
<div className={css(styles.calendarMonthHeaderNavControl, 'pf-m-prev-month')}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,23 @@ test('InlineProps render correct wrapper component and attributes', () => {
const title = screen.getByText('Title');
expect(title).toBeVisible();
});

test('Renders with custom ouiaId', () => {
const { container } = render(<CalendarMonth date={new Date(2024, 0, 15)} ouiaId="test-id" />);
expect(container.firstChild).toHaveAttribute('data-ouia-component-id', 'test-id');
});

test('Renders with expected ouia component type', () => {
const { container } = render(<CalendarMonth date={new Date(2024, 0, 15)} ouiaId="test-id" />);
expect(container.firstChild).toHaveAttribute('data-ouia-component-type', 'PF6/CalendarMonth');
});

test('Renders with ouiaSafe defaulting to true', () => {
const { container } = render(<CalendarMonth date={new Date(2024, 0, 15)} ouiaId="test-id" />);
expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'true');
});

test('Renders with ouiaSafe=false when specified', () => {
const { container } = render(<CalendarMonth date={new Date(2024, 0, 15)} ouiaId="test-id" ouiaSafe={false} />);
expect(container.firstChild).toHaveAttribute('data-ouia-safe', 'false');
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ exports[`With popover opened 1`] = `
>
<div
class="pf-v6-c-calendar-month"
data-ouia-component-id="OUIA-Generated-CalendarMonth-:rs:"
data-ouia-component-type="PF6/CalendarMonth"
data-ouia-safe="true"
>
<div
class="pf-v6-c-calendar-month__header"
Expand All @@ -96,7 +99,7 @@ exports[`With popover opened 1`] = `
<button
aria-label="Previous month"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-:rt:"
data-ouia-component-id="OUIA-Generated-Button-plain-:ru:"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
type="button"
Expand Down Expand Up @@ -131,15 +134,15 @@ exports[`With popover opened 1`] = `
>
<span
hidden=""
id="hidden-month-span:rs:"
id="hidden-month-span:rt:"
>
Month
</span>
<button
aria-expanded="false"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r10:"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r11:"
data-ouia-component-type="PF6/MenuToggle"
data-ouia-safe="true"
style="width: 140px;"
Expand Down Expand Up @@ -186,7 +189,7 @@ exports[`With popover opened 1`] = `
<input
aria-invalid="false"
aria-label="Select year"
data-ouia-component-id="OUIA-Generated-TextInputBase-:r12:"
data-ouia-component-id="OUIA-Generated-TextInputBase-:r13:"
data-ouia-component-type="PF6/TextInput"
data-ouia-safe="true"
type="number"
Expand All @@ -202,7 +205,7 @@ exports[`With popover opened 1`] = `
<button
aria-label="Next month"
class="pf-v6-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-:r13:"
data-ouia-component-id="OUIA-Generated-Button-plain-:r14:"
data-ouia-component-type="PF6/Button"
data-ouia-safe="true"
type="button"
Expand Down
1 change: 1 addition & 0 deletions packages/react-core/src/helpers/OUIA/OUIA.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ component.
* [Alert](/components/alert)
* [Breadcrumb](/components/breadcrumb)
* [Button](/components/button)
* [CalendarMonth](/components/calendar-month)
* [Card](/components/card)
* [Checkbox](/components/forms/checkbox)
* [Chip](/components/chip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r73:"
Expand Down Expand Up @@ -242,7 +241,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r78:"
Expand Down Expand Up @@ -324,7 +322,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r7d:"
Expand Down Expand Up @@ -406,7 +403,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r7i:"
Expand Down Expand Up @@ -488,7 +484,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r7n:"
Expand Down Expand Up @@ -570,7 +565,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r7s:"
Expand Down Expand Up @@ -652,7 +646,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r81:"
Expand Down Expand Up @@ -734,7 +727,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r86:"
Expand Down Expand Up @@ -816,7 +808,6 @@ exports[`Table Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r8b:"
Expand Down Expand Up @@ -6706,7 +6697,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r5f:"
Expand Down Expand Up @@ -6788,7 +6778,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r5k:"
Expand Down Expand Up @@ -6870,7 +6859,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r5p:"
Expand Down Expand Up @@ -6952,7 +6940,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r5u:"
Expand Down Expand Up @@ -7034,7 +7021,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r63:"
Expand Down Expand Up @@ -7116,7 +7102,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r68:"
Expand Down Expand Up @@ -7198,7 +7183,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r6d:"
Expand Down Expand Up @@ -7280,7 +7264,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r6i:"
Expand Down Expand Up @@ -7362,7 +7345,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r6n:"
Expand Down Expand Up @@ -7444,7 +7426,6 @@ exports[`Table Simple Actions table 1`] = `
>
<button
aria-expanded="false"
aria-haspopup="menu"
aria-label="Kebab toggle"
class="pf-v6-c-menu-toggle pf-m-plain pf-m-disabled"
data-ouia-component-id="OUIA-Generated-MenuToggle-plain-:r6s:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`Dropdown items Matches snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="true"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle pf-m-expanded"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-:r4j:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down Expand Up @@ -45,7 +44,6 @@ exports[`Dropdown toggle Matches snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="false"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle"
data-ouia-component-id="OUIA-Generated-MenuToggle-default-:r2d:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`checkbox select with no props snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="false"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r2:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down Expand Up @@ -46,7 +45,6 @@ exports[`opened checkbox select snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="true"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle pf-m-expanded"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r5:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ exports[`MultiTypeaheadSelect Matches snapshot 1`] = `
</div>
<button
aria-expanded="true"
aria-haspopup="menu"
aria-label="Multi select Typeahead menu toggle"
class="pf-v6-c-menu-toggle__button"
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-:r4t:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exports[`Matches snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="true"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle pf-m-expanded"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r22:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down Expand Up @@ -46,7 +45,6 @@ exports[`checkbox select with no props snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="false"
aria-haspopup="menu"
class="pf-v6-c-menu-toggle"
data-ouia-component-id="OUIA-Generated-MenuToggle-:r1v:"
data-ouia-component-type="PF6/MenuToggle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ exports[`Matches snapshot 1`] = `
</div>
<button
aria-expanded="true"
aria-haspopup="menu"
aria-label="Typeahead menu toggle"
class="pf-v6-c-menu-toggle__button"
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-:r4h:"
Expand Down
Loading