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

fix(Menu): allow scrolling inside #367

Merged
merged 4 commits into from
Aug 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-jars-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cube-dev/ui-kit": patch
---

Allow scrolling inside the Menu component.
18 changes: 15 additions & 3 deletions src/components/overlays/Dialog/DialogTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useOverlayTriggerState } from '@react-stately/overlays';
import { PressResponder } from '@react-aria/interactions';
import { useMediaQuery } from '@react-spectrum/utils';
import { useOverlayPosition, useOverlayTrigger } from '@react-aria/overlays';
import { OverlayTriggerProps, PositionProps } from '@react-types/overlays';

import { Modal, Popover, Tray, WithCloseBehavior } from '../Modal';
import { Styles } from '../../../tasty';
Expand All @@ -11,7 +12,10 @@ import { DialogContext } from './context';

export type CubeDialogClose = (close: () => void) => ReactElement;

export interface CubeDialogTriggerProps extends WithCloseBehavior {
export interface CubeDialogTriggerProps
extends OverlayTriggerProps,
PositionProps,
WithCloseBehavior {
/** The Dialog and its trigger element. See the DialogTrigger [Content section](#content) for more information on what to provide as children. */
children: [ReactElement, CubeDialogClose | ReactElement];
/**
Expand Down Expand Up @@ -42,9 +46,10 @@ export interface CubeDialogTriggerProps extends WithCloseBehavior {
/** The style map for the overlay **/
styles?: Styles;
shouldCloseOnInteractOutside?: (element: Element) => boolean;
onDismiss?: (action?: string) => void;
}

function DialogTrigger(props) {
function DialogTrigger(props: CubeDialogTriggerProps) {
let {
children,
type = 'modal',
Expand Down Expand Up @@ -193,6 +198,7 @@ function PopoverTrigger(allProps) {
isKeyboardDismissDisabled,
hideOnClose,
shouldCloseOnInteractOutside,
keepOpenOnScroll,
...props
} = allProps;

Expand All @@ -215,9 +221,15 @@ function PopoverTrigger(allProps) {
isOpen: state.isOpen,
});

let overlayTriggerState = state;

if (keepOpenOnScroll) {
overlayTriggerState = { ...state, close: updatePosition };
}

let { triggerProps, overlayProps } = useOverlayTrigger(
{ type: 'dialog' },
state,
overlayTriggerState,
triggerRef,
);

Expand Down
6 changes: 3 additions & 3 deletions src/components/overlays/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ const ModalElement = tasty({
});

export interface CubeModalProps
extends Omit<ModalProps, 'container'>,
extends Omit<ModalProps, 'container' | 'type'>,
WithCloseBehavior {
container?: HTMLElement;
qa?: BaseProps['qa'];
onClose?: (action?: string) => void;
type?: 'modal' | 'fullscreen' | 'fullscreenTakeover';
type?: 'modal' | 'fullscreen' | 'fullscreenTakeover' | 'panel';
styles?: Styles;
shouldCloseOnInteractOutside?: (element: Element) => boolean;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ interface ModalWrapperProps extends TransitionState {
children?: ReactNode;
qa?: BaseProps['qa'];
isOpen?: boolean;
type?: 'modal' | 'fullscreen' | 'fullscreenTakeover';
type?: 'modal' | 'fullscreen' | 'fullscreenTakeover' | 'panel';
placement?: 'top' | 'bottom';
styles?: Styles;
overlayProps?: Props;
Expand Down
3 changes: 2 additions & 1 deletion src/components/pickers/Menu/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const StyledMenu = tasty({
sections: '0', // has sections inside
},
overflow: {
'': 'hidden',
'': 'auto',
section: '',
},
border: {
Expand All @@ -33,6 +33,7 @@ export const StyledMenu = tasty({
'': '',
popover: '0px 5px 15px #dark.05',
},
styledScrollbar: true,
},
});

Expand Down
Loading