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

ASAP-899 Fix scroll issue on assign users modal #4520

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
11 changes: 10 additions & 1 deletion packages/react-components/src/atoms/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export type MultiSelectProps<
readonly id?: string;
readonly enabled?: boolean;
readonly placeholder?: string;
readonly onFocus?: () => void;
readonly onChange?: M extends true
? MultiSelectOnChange<T>
: SingleSelectOnChange<T>;
Expand Down Expand Up @@ -191,6 +192,7 @@ const MultiSelect = <
placeholder = '',
maxMenuHeight,
noOptionsMessage,
onFocus = noop,
onChange = noop,
sortable = true,
creatable = false,
Expand Down Expand Up @@ -278,7 +280,13 @@ const MultiSelect = <
ref: (ref: RefType<T>) => {
inputRef = ref;
},
onFocus: checkValidation,
onFocus: () => {
if (onFocus) {
onFocus();
}

checkValidation();
},
onBlur: checkValidation,
onChange: (
options: M extends true ? OptionsType<T> : T | null,
Expand Down Expand Up @@ -333,6 +341,7 @@ const MultiSelect = <
loadOptions={loadOptions}
cacheOptions
defaultOptions
maxMenuHeight={maxMenuHeight}
/>
)}
<input
Expand Down
39 changes: 26 additions & 13 deletions packages/react-components/src/molecules/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentProps } from 'react';
import { ComponentProps, useEffect } from 'react';
import { css, SerializedStyles } from '@emotion/react';

import { Card, Overlay } from '../atoms';
Expand All @@ -17,6 +17,7 @@ const overlayContainerStyles = css({
top: 0,
left: 0,
zIndex: 1,
overflow: 'hidden',
});

const modalContainerStyles = css({
Expand All @@ -29,6 +30,7 @@ const modalContainerStyles = css({
});
const overlayStyles = css({
gridArea: '1 / 1',
overflow: 'hidden',
});
const modalStyles = css({
gridArea: '1 / 1',
Expand Down Expand Up @@ -62,19 +64,30 @@ const Modal: React.FC<ModalProps> = ({
padding,
children,
overrideModalStyles,
}) => (
<div css={overlayContainerStyles}>
<div css={modalContainerStyles}>
<div css={overlayStyles}>
<Overlay />
</div>
<div role="dialog" css={css([modalStyles, overrideModalStyles])}>
<Card padding={padding}>
<div css={scrollStyles}>{children}</div>
</Card>
}) => {
useEffect(() => {
const originalStyle = window.getComputedStyle(document.body).overflow;
document.body.style.overflow = 'hidden';

return () => {
document.body.style.overflow = originalStyle;
};
}, []);

return (
<div css={overlayContainerStyles}>
<div css={modalContainerStyles}>
<div css={overlayStyles}>
<Overlay />
</div>
<div role="dialog" css={css([modalStyles, overrideModalStyles])}>
<Card padding={padding}>
<div css={scrollStyles}>{children}</div>
</Card>
</div>
</div>
</div>
</div>
);
);
};

export default Modal;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css } from '@emotion/react';
import { ComponentProps, useState } from 'react';
import { ComponentProps, useRef, useState } from 'react';
import { useForm } from 'react-hook-form';
import { AuthorSelect, OptionsType } from '..';
import { Button, Headline3, Paragraph, Subtitle } from '../atoms';
Expand Down Expand Up @@ -118,6 +118,7 @@ const ComplianceAssignUsersModal: React.FC<ComplianceAssignUsersModalProps> = ({
getAssignedUsersSuggestions,
assignedUsers,
}) => {
const bottomDivRef = useRef<HTMLDivElement>(null);
const { setValue, watch, handleSubmit } = useForm<AssignedUsersFormData>({
mode: 'onBlur',
defaultValues: {
Expand Down Expand Up @@ -164,6 +165,14 @@ const ComplianceAssignUsersModal: React.FC<ComplianceAssignUsersModalProps> = ({
<InformationRow title="APC Coverage" value={apcCoverage} />

<AuthorSelect
maxMenuHeight={170}
onFocus={() => {
if (bottomDivRef.current) {
bottomDivRef.current.scrollIntoView({
behavior: 'smooth',
});
}
}}
isMulti
creatable={false}
title="Assign User"
Expand All @@ -181,7 +190,7 @@ const ComplianceAssignUsersModal: React.FC<ComplianceAssignUsersModalProps> = ({
/>
</div>

<div css={buttonContainerStyles}>
<div css={buttonContainerStyles} ref={bottomDivRef}>
<div css={dismissButtonStyles}>
<Button enabled={!isSubmitting} onClick={onDismiss}>
Cancel
Expand Down