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(Page): add event param to onNotificationDrawerExpand and onPageResize. #9011

Merged
merged 3 commits into from
May 2, 2023
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
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export interface DrawerProps extends React.HTMLProps<HTMLDivElement> {
/** Position of the drawer panel */
position?: 'left' | 'right' | 'bottom';
/** Callback when drawer panel is expanded after waiting 250ms for animation to complete. */
onExpand?: () => void;
onExpand?: (event: KeyboardEvent | React.MouseEvent | React.TransitionEvent) => void;
}

export interface DrawerContextProps {
isExpanded: boolean;
isStatic: boolean;
onExpand?: () => void;
onExpand?: (event: KeyboardEvent | React.MouseEvent | React.TransitionEvent) => void;
position?: string;
drawerRef?: React.RefObject<HTMLDivElement>;
drawerContentRef?: React.RefObject<HTMLDivElement>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
drawerRef.current.classList.remove(css(styles.modifiers.resizing));
isResizing = false;
onResize && onResize(e, currWidth, id);
setInitialVals = true;

Check warning on line 178 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

Assignments to the 'setInitialVals' variable from inside React Hook React.useCallback will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside React.useCallback
document.removeEventListener('mousemove', callbackMouseMove);
document.removeEventListener('mouseup', callbackMouseUp);
};
Expand All @@ -191,9 +191,9 @@
document.removeEventListener('touchend', callbackTouchEnd);
};

const callbackMouseMove = React.useCallback(handleMouseMove, []);

Check warning on line 194 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook React.useCallback has missing dependencies: 'handleControlMove' and 'position'. Either include them or remove the dependency array
const callbackTouchEnd = React.useCallback(handleTouchEnd, []);

Check warning on line 195 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook React.useCallback has missing dependencies: 'callbackTouchEnd', 'callbackTouchMove', 'currWidth', 'id', and 'onResize'. Either include them or remove the dependency array. If 'onResize' changes too often, find the parent component that defines it and wrap that definition in useCallback
const callbackTouchMove = React.useCallback(handleTouchMove, []);

Check warning on line 196 in packages/react-core/src/components/Drawer/DrawerPanelContent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook React.useCallback has missing dependencies: 'handleControlMove' and 'position'. Either include them or remove the dependency array
const callbackMouseUp = React.useCallback(handleMouseup, []);

const handleKeys = (e: React.KeyboardEvent) => {
Expand Down Expand Up @@ -263,7 +263,7 @@
onTransitionEnd={(ev) => {
if (ev.target as HTMLElement === panel.current) {
if (!hidden && ev.nativeEvent.propertyName === 'transform') {
onExpand();
onExpand(ev);
}
setIsExpandedInternal(!hidden);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/react-core/src/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface PageProps extends React.HTMLProps<HTMLDivElement> {
/** Flag indicating if breadcrumb width should be limited */
isBreadcrumbWidthLimited?: boolean;
/** Callback when notification drawer panel is finished expanding. */
onNotificationDrawerExpand?: () => void;
onNotificationDrawerExpand?: (event: KeyboardEvent | React.MouseEvent | React.TransitionEvent) => void;
/** Skip to content component for the page */
skipToContent?: React.ReactElement;
/** Sets the value for role on the <main> element */
Expand All @@ -54,7 +54,7 @@ export interface PageProps extends React.HTMLProps<HTMLDivElement> {
* Can add callback to be notified when resize occurs, for example to set the sidebar isSidebarOpen prop to false for a width < 768px
* Returns object { mobileView: boolean, windowSize: number }
*/
onPageResize?: ((object: any) => void) | null;
onPageResize?: ((event: MouseEvent | TouchEvent | React.KeyboardEvent, object: any) => void) | null;
/**
* The page resize observer uses the breakpoints returned from this function when adding the pf-m-breakpoint-[default|sm|md|lg|xl|2xl] class
* You can override the default getBreakpoint function to return breakpoints at different sizes than the default
Expand Down Expand Up @@ -163,11 +163,11 @@ export class Page extends React.Component<PageProps, PageState> {
// eslint-disable-next-line radix
this.getWindowWidth() < Number.parseInt(globalBreakpointXl.value, 10);

resize = () => {
resize = (_event?: MouseEvent | TouchEvent | React.KeyboardEvent<Element>) => {
const { onPageResize } = this.props;
const mobileView = this.isMobile();
if (onPageResize) {
onPageResize({ mobileView, windowSize: this.getWindowWidth() });
onPageResize(_event, { mobileView, windowSize: this.getWindowWidth() });
}
if (mobileView !== this.state.mobileView) {
this.setState({ mobileView });
Expand Down Expand Up @@ -324,7 +324,7 @@ export class Page extends React.Component<PageProps, PageState> {
{sidebar}
{notificationDrawer && (
<div className={css(styles.pageDrawer)}>
<Drawer isExpanded={isNotificationDrawerExpanded} onExpand={onNotificationDrawerExpand}>
<Drawer isExpanded={isNotificationDrawerExpanded} onExpand={(event) => onNotificationDrawerExpand(event)}>
<DrawerContent panelContent={panelContent}>
<DrawerContentBody>{main}</DrawerContentBody>
</DrawerContent>
Expand Down
4 changes: 2 additions & 2 deletions packages/react-core/src/demos/Nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ class PageLayoutManualNav extends React.Component {
});
};

this.onPageResize = ({ mobileView, windowSize }) => {
this.onPageResize = (_event, { mobileView, windowSize }) => {
this.setState({
isMobileView: mobileView
});
Expand Down Expand Up @@ -1428,7 +1428,7 @@ class PageLayoutManualNav extends React.Component {
<Page
header={Header}
sidebar={Sidebar}
onPageResize={this.onPageResize}
onPageResize={(event) => this.onPageResize(event)}
skipToContent={PageSkipToContent}
mainContainerId={pageId}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class BasicNotificationDrawer extends React.Component {
});
};

this.focusDrawer = () => {
this.focusDrawer = (_event) => {
const firstTabbableItem = this.drawerRef.current.querySelector('a, button');
firstTabbableItem.focus();
};
Expand Down Expand Up @@ -549,7 +549,7 @@ class BasicNotificationDrawer extends React.Component {
sidebar={Sidebar}
isManagedSidebar
notificationDrawer={notificationDrawer}
onNotificationDrawerExpand={this.focusDrawer}
onNotificationDrawerExpand={(event) => this.focusDrawer(event)}
isNotificationDrawerExpanded={isDrawerExpanded}
skipToContent={PageSkipToContent}
breadcrumb={PageBreadcrumb}
Expand Down Expand Up @@ -790,7 +790,7 @@ class GroupedNotificationDrawer extends React.Component {
});
};

this.focusDrawer = () => {
this.focusDrawer = (_event) => {
// Prevent the NotificationDrawer from receiving focus if a drawer group item is opened
if (!document.activeElement.closest(`.${this.drawerRef.current.className}`)) {
const firstTabbableItem = this.drawerRef.current.querySelector('a, button');
Expand Down Expand Up @@ -1313,7 +1313,7 @@ class GroupedNotificationDrawer extends React.Component {
isManagedSidebar
notificationDrawer={notificationDrawer}
isNotificationDrawerExpanded={isDrawerExpanded}
onNotificationDrawerExpand={this.focusDrawer}
onNotificationDrawerExpand={(event) => this.focusDrawer(event)}
skipToContent={PageSkipToContent}
breadcrumb={PageBreadcrumb}
mainContainerId={pageId}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/demos/examples/DashboardWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class DashboardWrapper extends React.Component {
mainContainerId={mainContainerId ? mainContainerId : 'main-content-page-layout-default-nav'}
notificationDrawer={notificationDrawer}
isNotificationDrawerExpanded={isNotificationDrawerExpanded}
onPageResize={onPageResize}
onPageResize={(event) => onPageResize(event)}
{...pageProps}
>
{hasPageTemplateTitle && PageTemplateTitle}
Expand Down