Skip to content

Commit 22fb583

Browse files
author
Eric Olkowski
committed
feat(Menu): consumed Penta updates
1 parent 32be844 commit 22fb583

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export interface ButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'r
9595
innerRef?: React.Ref<any>;
9696
/** Adds count number to button */
9797
countOptions?: BadgeCountObject;
98+
/** @hide Sets the role of the button. Should only be used when the button is a descendant of a menu or tablist. */
99+
role?: 'menuitem' | 'tab';
98100
/** Value to overwrite the randomly generated data-ouia-component-id.*/
99101
ouiaId?: number | string;
100102
/** 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. */
@@ -124,6 +126,7 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
124126
iconPosition = 'start',
125127
'aria-label': ariaLabel = null,
126128
icon = null,
129+
role,
127130
ouiaId,
128131
ouiaSafe = true,
129132
tabIndex = null,
@@ -182,7 +185,7 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
182185
disabled={isButtonElement ? isDisabled : null}
183186
tabIndex={tabIndex !== null ? tabIndex : getDefaultTabIdx()}
184187
type={isButtonElement || isInlineSpan ? type : null}
185-
role={isInlineSpan ? 'button' : null}
188+
role={isInlineSpan ? 'button' : role}
186189
ref={innerRef}
187190
{...ouiaProps}
188191
>

packages/react-core/src/components/CalendarMonth/examples/CalendarMonth.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ propComponents: ['CalendarMonth', 'CalendarFormat', 'CalendarMonthInlineProps']
1111
### Selectable date
1212

1313
```ts file="./CalendarMonthSelectableDate.tsx"
14+
1415
```
1516

1617
### Date range
1718

1819
In this example, there are 2 dates selected: a range start date (via the `rangeStart` prop) and a range end date (via the `date` prop). Additionally, any dates prior to the range start date are disabled by passing in an array of functions to the `validators` prop. In this case a single function is passed in, which checks whether a date is greater than or equal to the range start date.
1920

20-
For this example, these dates are static and cannot be updated. For an interactive demo, see our [Date picker demos](https://www.patternfly.org/v4/components/date-picker/react-demos).
21+
For this example, these dates are static and cannot be updated. For an interactive demo, see our [Date picker demos](/components/date-and-time/date-picker/react-demos).
2122

2223
```ts file="./CalendarMonthDateRange.tsx"
24+
2325
```

packages/react-core/src/components/Menu/MenuItemAction.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import styles from '@patternfly/react-styles/css/components/Menu/menu';
33
import { css } from '@patternfly/react-styles';
44
import StarIcon from '@patternfly/react-icons/dist/esm/icons/star-icon';
55
import { MenuContext, MenuItemContext } from './MenuContext';
6-
7-
export interface MenuItemActionProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'type' | 'ref'> {
6+
import { Button } from '../Button';
7+
export interface MenuItemActionProps extends React.HTMLProps<HTMLDivElement> {
88
/** Additional classes added to the action button */
99
className?: string;
1010
/** The action icon to use */
@@ -24,7 +24,7 @@ export interface MenuItemActionProps extends Omit<React.HTMLProps<HTMLButtonElem
2424
}
2525

2626
const MenuItemActionBase: React.FunctionComponent<MenuItemActionProps> = ({
27-
className = '',
27+
className,
2828
icon,
2929
onClick,
3030
'aria-label': ariaLabel,
@@ -45,24 +45,29 @@ const MenuItemActionBase: React.FunctionComponent<MenuItemActionProps> = ({
4545
onActionClick && onActionClick(event, itemId, actionId);
4646
};
4747
return (
48-
<button
48+
<div
4949
className={css(
5050
styles.menuItemAction,
5151
isFavorited !== null && 'pf-m-favorite',
5252
isFavorited && styles.modifiers.favorited,
5353
className
5454
)}
55-
aria-label={ariaLabel}
56-
onClick={onClickButton}
57-
{...((isDisabled === true || isDisabledContext === true) && { disabled: true })}
58-
ref={innerRef}
59-
tabIndex={-1}
6055
{...props}
6156
>
62-
<span className={css(styles.menuItemActionIcon)}>
63-
{icon === 'favorites' || isFavorited !== null ? <StarIcon aria-hidden /> : icon}
64-
</span>
65-
</button>
57+
<Button
58+
aria-label={ariaLabel}
59+
onClick={onClickButton}
60+
ref={innerRef}
61+
role="menuitem"
62+
variant="plain"
63+
tabIndex={-1}
64+
isDisabled={isDisabled || isDisabledContext}
65+
>
66+
<span className={css(styles.menuItemActionIcon)}>
67+
{icon === 'favorites' || isFavorited !== null ? <StarIcon aria-hidden /> : icon}
68+
</span>
69+
</Button>
70+
</div>
6671
);
6772
}}
6873
</MenuItemContext.Consumer>

packages/react-core/src/helpers/KeyboardHandler.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,30 @@ export const handleArrows = (
106106

107107
if (!activeRow.length || onlyTraverseSiblings) {
108108
let nextSibling = activeElement;
109-
// While a sibling exists, check each sibling to determine if it should be focussed
109+
110110
while (nextSibling) {
111-
// Set the next checked sibling, determined by the horizontal arrow key direction
112-
nextSibling = key === 'ArrowLeft' ? nextSibling.previousElementSibling : nextSibling.nextElementSibling;
111+
const isDirectChildOfNavigableElement = nextSibling.parentElement === element;
112+
const nextSiblingMainElement = isDirectChildOfNavigableElement ? nextSibling : nextSibling.parentElement;
113+
nextSibling =
114+
key === 'ArrowLeft'
115+
? nextSiblingMainElement.previousElementSibling
116+
: nextSiblingMainElement.nextElementSibling;
117+
113118
if (nextSibling) {
114119
if (validSiblingTags.includes(nextSibling.tagName)) {
115-
// If the sibling's tag is included in validSiblingTags, set the next target element and break the loop
116120
moveTarget = nextSibling;
117121
break;
118122
}
119-
// If the sibling's tag is not valid, skip to the next sibling if possible
123+
// For cases where the validSiblingTag is inside a div wrapper
124+
if (validSiblingTags.includes(nextSibling.children[0].tagName)) {
125+
moveTarget = nextSibling.children[0];
126+
break;
127+
}
120128
}
121129
}
122130
} else {
123131
activeRow.forEach((focusableElement, index) => {
124132
if (event.target === focusableElement) {
125-
// Once found, move up or down the array by 1. Determined by the vertical arrow key direction
126133
const increment = key === 'ArrowLeft' ? -1 : 1;
127134
currentIndex = index + increment;
128135
if (currentIndex >= activeRow.length) {
@@ -132,7 +139,6 @@ export const handleArrows = (
132139
currentIndex = activeRow.length - 1;
133140
}
134141

135-
// Set the next target element
136142
moveTarget = activeRow[currentIndex];
137143
}
138144
});

0 commit comments

Comments
 (0)