Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const buildCalendar = (year: number, month: number, weekStart: number, validator
const date = new Date(firstDayOfWeek);
week.push({
date,
isValid: validators.every(validator => validator(date))
isValid: validators.every((validator) => validator(date))
});
firstDayOfWeek.setDate(firstDayOfWeek.getDate() + 1);
}
Expand All @@ -129,10 +129,10 @@ const today = new Date();
export const CalendarMonth = ({
date: dateProp,
locale = undefined,
monthFormat = date => date.toLocaleDateString(locale, { month: 'long' }),
weekdayFormat = date => date.toLocaleDateString(locale, { weekday: 'narrow' }),
longWeekdayFormat = date => date.toLocaleDateString(locale, { weekday: 'long' }),
dayFormat = date => date.getDate(),
monthFormat = (date) => date.toLocaleDateString(locale, { month: 'long' }),
weekdayFormat = (date) => date.toLocaleDateString(locale, { weekday: 'narrow' }),
longWeekdayFormat = (date) => date.toLocaleDateString(locale, { weekday: 'long' }),
dayFormat = (date) => date.getDate(),
weekStart = 0, // Use the American Sunday as a default
onChange = () => {},
validators = [() => true],
Expand All @@ -148,7 +148,9 @@ export const CalendarMonth = ({
inlineProps,
...props
}: CalendarProps) => {
const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(monthNum => new Date(1990, monthNum)).map(monthFormat);
const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
.map((monthNum) => new Date(1990, monthNum))
.map(monthFormat);
const [isSelectOpen, setIsSelectOpen] = React.useState(false);
// eslint-disable-next-line prefer-const
const [focusedDate, setFocusedDate] = React.useState(() => {
Expand All @@ -168,7 +170,7 @@ export const CalendarMonth = ({
const [hiddenMonthId] = React.useState(getUniqueId('hidden-month-span'));
const [shouldFocus, setShouldFocus] = React.useState(false);

const isValidated = (date: Date) => validators.every(validator => validator(date));
const isValidated = (date: Date) => validators.every((validator) => validator(date));
const focusedDateValidated = isValidated(focusedDate);
useEffect(() => {
if (isValidDate(dateProp) && !isSameDate(focusedDate, dateProp)) {
Expand Down Expand Up @@ -224,12 +226,10 @@ export const CalendarMonth = ({
const nextMonth = addMonth(1);
const focusedYear = focusedDate.getFullYear();
const focusedMonth = focusedDate.getMonth();
const calendar = React.useMemo(() => buildCalendar(focusedYear, focusedMonth, weekStart, validators), [
focusedYear,
focusedMonth,
weekStart,
validators
]);
const calendar = React.useMemo(
() => buildCalendar(focusedYear, focusedMonth, weekStart, validators),
[focusedYear, focusedMonth, weekStart, validators]
);
if (!focusedDateValidated) {
const toFocus = calendar
.reduce((acc, cur) => [...acc, ...cur], [])
Expand Down Expand Up @@ -299,7 +299,7 @@ export const CalendarMonth = ({
>
<SelectList>
{longMonths.map((longMonth, index) => (
<SelectOption key={index} itemId={index} isSelected={longMonth === monthFormatted}>
<SelectOption key={index} value={index} isSelected={longMonth === monthFormatted}>
{longMonth}
</SelectOption>
))}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-core/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface DropdownProps extends MenuProps, OUIAProps {
/** Flag indicating the toggle should be focused after a selection. If this use case is too restrictive, the optional toggleRef property with a node toggle may be used to control focus. */
shouldFocusToggleOnSelect?: boolean;
/** Function callback called when user selects item. */
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, itemId?: string | number) => void;
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void;
/** Callback to allow the dropdown component to change the open state of the menu.
* Triggered by clicking outside of the menu, or by pressing any keys specificed in onOpenChangeKeys. */
onOpenChange?: (isOpen: boolean) => void;
Expand Down Expand Up @@ -138,8 +138,8 @@ const DropdownBase: React.FunctionComponent<DropdownProps> = ({
<Menu
className={css(className)}
ref={menuRef}
onSelect={(event, itemId) => {
onSelect && onSelect(event, itemId);
onSelect={(event, value) => {
onSelect && onSelect(event, value);
shouldFocusToggleOnSelect && toggleRef.current.focus();
}}
isPlain={isPlain}
Expand Down
14 changes: 8 additions & 6 deletions packages/react-core/src/components/Dropdown/DropdownItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'>, OUIAProps
/** Render item as disabled option */
isDisabled?: boolean;
/** Identifies the component in the dropdown onSelect callback */
itemId?: any;
value?: any;
/** Callback for item click */
onClick?: (event?: any) => void;
/** Value to overwrite the randomly generated data-ouia-component-id.*/
Expand All @@ -32,7 +32,7 @@ const DropdownItemBase: React.FunctionComponent<DropdownItemProps> = ({
className,
description,
isDisabled,
itemId,
value,
onClick,
ouiaId,
ouiaSafe,
Expand All @@ -45,7 +45,7 @@ const DropdownItemBase: React.FunctionComponent<DropdownItemProps> = ({
className={css(className)}
description={description}
isDisabled={isDisabled}
itemId={itemId}
itemId={value}
onClick={onClick}
ref={innerRef}
{...ouiaProps}
Expand All @@ -56,8 +56,10 @@ const DropdownItemBase: React.FunctionComponent<DropdownItemProps> = ({
);
};

export const DropdownItem = React.forwardRef((props: DropdownItemProps, ref: React.Ref<HTMLAnchorElement | HTMLButtonElement>) => (
<DropdownItemBase {...props} innerRef={ref} />
));
export const DropdownItem = React.forwardRef(
(props: DropdownItemProps, ref: React.Ref<HTMLAnchorElement | HTMLButtonElement>) => (
<DropdownItemBase {...props} innerRef={ref} />
)
);

DropdownItem.displayName = 'DropdownItem';
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const DropdownBasic: React.FunctionComponent = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: string | number | undefined) => {
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
// eslint-disable-next-line no-console
console.log('selected', itemId);
console.log('selected', value);
setIsOpen(false);
};

Expand All @@ -28,29 +28,29 @@ export const DropdownBasic: React.FunctionComponent = () => {
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem itemId={0} key="action">
<DropdownItem value={0} key="action">
Action
</DropdownItem>
<DropdownItem
itemId={1}
value={1}
key="link"
to="#default-link2"
// Prevent the default onClick functionality for example purposes
onClick={(ev: any) => ev.preventDefault()}
>
Link
</DropdownItem>
<DropdownItem itemId={2} isDisabled key="disabled action">
<DropdownItem value={2} isDisabled key="disabled action">
Disabled Action
</DropdownItem>
<DropdownItem itemId={3} isDisabled key="disabled link" to="#default-link4">
<DropdownItem value={3} isDisabled key="disabled link" to="#default-link4">
Disabled Link
</DropdownItem>
<Divider component="li" key="separator" />
<DropdownItem itemId={4} key="separated action">
<DropdownItem value={4} key="separated action">
Separated Action
</DropdownItem>
<DropdownItem itemId={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
<DropdownItem value={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
Separated Link
</DropdownItem>
</DropdownList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const DropdownWithDescriptions: React.FunctionComponent = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: string | number | undefined) => {
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
// eslint-disable-next-line no-console
console.log('selected', itemId);
console.log('selected', value);
setIsOpen(false);
};

Expand All @@ -27,11 +27,11 @@ export const DropdownWithDescriptions: React.FunctionComponent = () => {
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem itemId={0} key="action" description="This is a description">
<DropdownItem value={0} key="action" description="This is a description">
Action
</DropdownItem>
<DropdownItem
itemId={1}
value={1}
key="link"
description="This is a very long description that describes the menu item"
to="#default-link2"
Expand All @@ -40,10 +40,10 @@ export const DropdownWithDescriptions: React.FunctionComponent = () => {
>
Link
</DropdownItem>
<DropdownItem itemId={2} isDisabled description="Disabled link description" key="disabled action">
<DropdownItem value={2} isDisabled description="Disabled link description" key="disabled action">
Disabled action
</DropdownItem>
<DropdownItem itemId={3} isDisabled description="This is a description" key="disabled link" to="#default-link4">
<DropdownItem value={3} isDisabled description="This is a description" key="disabled link" to="#default-link4">
Disabled link
</DropdownItem>
</DropdownList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const DropdownWithGroups: React.FunctionComponent = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: string | number | undefined) => {
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
// eslint-disable-next-line no-console
console.log('selected', itemId);
console.log('selected', value);
setIsOpen(false);
};

Expand All @@ -36,11 +36,11 @@ export const DropdownWithGroups: React.FunctionComponent = () => {
>
<DropdownGroup>
<DropdownList>
<DropdownItem itemId={0} key="action">
<DropdownItem value={0} key="action">
Action
</DropdownItem>
<DropdownItem
itemId={1}
value={1}
key="link"
to="#default-link2"
// Prevent the default onClick functionality for example purposes
Expand All @@ -53,21 +53,21 @@ export const DropdownWithGroups: React.FunctionComponent = () => {
<Divider component="li" />
<DropdownGroup label="Group 2" labelHeadingLevel="h3">
<DropdownList>
<DropdownItem itemId={2} key="group2 action">
<DropdownItem value={2} key="group2 action">
Group 2 action
</DropdownItem>
<DropdownItem itemId={3} key="group2 link" to="#default-link4" onClick={(ev: any) => ev.preventDefault()}>
<DropdownItem value={3} key="group2 link" to="#default-link4" onClick={(ev: any) => ev.preventDefault()}>
Group 2 link
</DropdownItem>
</DropdownList>
</DropdownGroup>
<Divider />
<DropdownGroup label="Group 3" labelHeadingLevel="h3">
<DropdownList>
<DropdownItem itemId={4} key="group3 action">
<DropdownItem value={4} key="group3 action">
Group 3 action
</DropdownItem>
<DropdownItem itemId={5} key="group3 link" to="#default-link6" onClick={(ev: any) => ev.preventDefault()}>
<DropdownItem value={5} key="group3 link" to="#default-link6" onClick={(ev: any) => ev.preventDefault()}>
Group 3 link
</DropdownItem>
</DropdownList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const DropdownWithKebab: React.FunctionComponent = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: string | number | undefined) => {
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
// eslint-disable-next-line no-console
console.log('selected', itemId);
console.log('selected', value);
setIsOpen(false);
};

Expand All @@ -34,29 +34,29 @@ export const DropdownWithKebab: React.FunctionComponent = () => {
shouldFocusToggleOnSelect
>
<DropdownList>
<DropdownItem itemId={0} key="action">
<DropdownItem value={0} key="action">
Action
</DropdownItem>
<DropdownItem
itemId={1}
value={1}
key="link"
to="#default-link2"
// Prevent the default onClick functionality for example purposes
onClick={(ev: any) => ev.preventDefault()}
>
Link
</DropdownItem>
<DropdownItem itemId={2} isDisabled key="disabled action">
<DropdownItem value={2} isDisabled key="disabled action">
Disabled Action
</DropdownItem>
<DropdownItem itemId={3} isDisabled key="disabled link" to="#default-link4">
<DropdownItem value={3} isDisabled key="disabled link" to="#default-link4">
Disabled Link
</DropdownItem>
<Divider component="li" key="separator" />
<DropdownItem itemId={4} key="separated action">
<DropdownItem value={4} key="separated action">
Separated Action
</DropdownItem>
<DropdownItem itemId={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
<DropdownItem value={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
Separated Link
</DropdownItem>
</DropdownList>
Expand Down
10 changes: 5 additions & 5 deletions packages/react-core/src/components/Form/examples/FormState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export const FormState = () => {
</MenuToggle>
)}
onOpenChange={(isOpen) => setIsSelectOpen(isOpen)}
onSelect={(_, itemId) => {
setValue('select-id', itemId as string);
onSelect={(_, value) => {
setValue('select-id', value as string);
setIsSelectOpen(false);
}}
>
<SelectList>
<SelectOption itemId="Option 1">Option 1</SelectOption>
<SelectOption itemId="Option 2">Option 2</SelectOption>
<SelectOption itemId="Option 3">Option 3</SelectOption>
<SelectOption value="Option 1">Option 1</SelectOption>
<SelectOption value="Option 2">Option 2</SelectOption>
<SelectOption value="Option 3">Option 3</SelectOption>
</SelectList>
</Select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ export const HintBasicWithTitle: React.FunctionComponent = () => {
)}
>
<DropdownList>
<DropdownItem itemId={0} key="action">
<DropdownItem value={0} key="action">
Action
</DropdownItem>
<DropdownItem
itemId={1}
value={1}
key="link"
to="#default-link2"
// Prevent the default onClick functionality for example purposes
onClick={(ev: any) => ev.preventDefault()}
>
Link
</DropdownItem>
<DropdownItem itemId={2} isDisabled key="disabled action">
<DropdownItem value={2} isDisabled key="disabled action">
Disabled Action
</DropdownItem>
<DropdownItem itemId={3} isDisabled key="disabled link" to="#default-link4">
<DropdownItem value={3} isDisabled key="disabled link" to="#default-link4">
Disabled Link
</DropdownItem>
<Divider component="li" key="separator" />
<DropdownItem itemId={4} key="separated action">
<DropdownItem value={4} key="separated action">
Separated Action
</DropdownItem>
<DropdownItem itemId={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
<DropdownItem value={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}>
Separated Link
</DropdownItem>
</DropdownList>
Expand Down
Loading