Skip to content

Commit

Permalink
fix(modal): fix comments issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xchaikax committed Dec 29, 2020
1 parent 73dc519 commit 3c5c9e2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 53 deletions.
17 changes: 16 additions & 1 deletion packages/modal/src/Component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,22 @@ import { version } from '../package.json';
hideBackdrop={boolean('hide backdrop', false)}
footer={showFooter && footerContent}
>
<div>Modal content</div>
<div>
<h3>Modal content</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim
ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia
consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque
porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,
quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut
aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit
qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum
qui dolorem eum fugiat quo voluptas nulla pariatur?
</p>
</div>
</Modal>
</React.Fragment>
);
Expand Down
42 changes: 20 additions & 22 deletions packages/modal/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
const handleMounted = () => {
manager.mount(getModal());

// Fix a bug on Chrome where the scroll isn't initially 0.
if (modalRef.current) {
modalRef.current.scrollTop = 0;
}
Expand Down Expand Up @@ -403,17 +402,19 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {

return (
<Portal ref={handlePortalRef} getPortalContainer={container}>
<div style={{ height }}>
<div
style={{ height }}
role='presentation'
data-test-id={dataTestId}
ref={handleRef}
onKeyDown={handleKeyDown}
>
<div
data-test-id={dataTestId}
onKeyDown={handleKeyDown}
role='presentation'
className={cn(styles.wrapper, {
[styles.hidden]: !open && exited,
[styles.wrapper_fullscreen]: fullscreen,
[styles.wrapper_small]: isSmall,
[styles.wrapperFullscreen]: fullscreen,
[styles.wrapperSmall]: isSmall,
})}
ref={handleRef}
>
{hideBackdrop ? null : (
<BackdropComponent
Expand All @@ -435,22 +436,21 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
>
<div
tabIndex={-1}
className={cn(styles.modal, styles[`modal_size_${size}`], {
[styles.modal_fullscreen]: fullscreen,
[styles.modal_small]: isSmall,
className={cn(styles.modal, styles[size], {
[styles.modalFullscreen]: fullscreen,
[styles.modalSmall]: isSmall,
})}
>
<div
className={cn(styles['flex-container'], {
[`${styles['flex-container_small']}`]: isSmall,
className={cn(styles.flexContainer, {
[styles.flexContainerSmall]: isSmall,
})}
>
<div
style={style}
className={cn(styles.content, className, {
[styles.content_small]: isSmall,
[styles.contentSmall]: isSmall,
})}
// сюда стили для транзишна контента
ref={contentRef}
>
{React.isValidElement(children)
Expand All @@ -461,8 +461,8 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {
{footer && (
<div
className={cn(styles.footer, {
[styles.footer_small]: isSmall,
[styles.footer_highlight]: shouldHighlightFooter,
[styles.footerSmall]: isSmall,
[styles.footerHighlight]: shouldHighlightFooter,
})}
>
{footer}
Expand All @@ -471,16 +471,14 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>((props, ref) => {

{hasCloser && (
<div
className={cn(styles['closer-wrapper'], {
[styles[
'closer-wrapper_highlight'
]]: shouldHighlightCloser,
className={cn(styles.closerWrapper, {
[styles.closerWrapperHighlight]: shouldHighlightCloser,
})}
>
<button
type='button'
className={cn([styles.closer], {
[styles.closer_small]: isSmall,
[styles.closerSmall]: isSmall,
})}
onClick={handleCloserClick}
>
Expand Down
7 changes: 3 additions & 4 deletions packages/modal/src/components/fade/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactNode, forwardRef } from 'react';
import { Transition } from 'react-transition-group';
import { TransitionStatus } from 'react-transition-group/Transition';
import Transition, { TransitionStatus } from 'react-transition-group/Transition';
import cn from 'classnames';
import mergeRefs from 'react-merge-refs';

Expand Down Expand Up @@ -102,12 +101,12 @@ export const Fade = forwardRef<Element, FadeProps>((props, ref) => {
onExit={handleExit}
onExited={handleExited}
>
{(status: string) => (
{(status: TransitionStatus) => (
<div
className={cn(
styles.fade,
{ [styles.hidden]: status === 'exited' && !show },
(styles as { [status: string]: TransitionStatus })[status],
styles[status],
className,
)}
data-test-id={dataTestId}
Expand Down
2 changes: 0 additions & 2 deletions packages/modal/src/components/fade/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
ExitHandler,
} from 'react-transition-group/Transition';

// TODO: перенести в alfalab/utils

/**
* Типы для свойств компонентов с анимацией
*/
Expand Down
30 changes: 15 additions & 15 deletions packages/modal/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
padding-bottom: var(--gap-xl);
}

.wrapper_fullscreen {
.wrapperFullscreen {
padding: 0;
background: transparent;
}

.wrapper_small {
.wrapperSmall {
padding: 0;
}

Expand All @@ -51,17 +51,17 @@
margin: auto;
}

.modal_size_s {
.s {
width: 476px;
padding: var(--gap-l) var(--gap-3xl) calc(var(--gap-l) + 6px);
}

.modal_size_l {
.l {
width: 800px;
padding: var(--gap-2xl) var(--gap-5xl) calc(var(--gap-2xl) + 6px);
}

.modal_fullscreen {
.modalFullscreen {
width: 100%;
max-width: 100%;
min-height: 100%;
Expand All @@ -70,7 +70,7 @@
border-radius: 0;
}

.modal_small {
.modalSmall {
display: flex;
flex-direction: column;
position: relative;
Expand All @@ -85,14 +85,14 @@
transform: none;
}

.flex-container {
.flexContainer {
width: 100%;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
}

.flex-container_small {
.flexContainerSmall {
height: 100%;
}

Expand All @@ -101,7 +101,7 @@
overflow: auto;
}

.content_small {
.contentSmall {
margin: 0;
padding: calc(var(--gap-4xl) + var(--gap-2xs)) var(--gap-m) var(--gap-l);
}
Expand All @@ -113,17 +113,17 @@
transition: border-top 0.4s;
}

.footer_small {
.footerSmall {
margin: 0;
padding: var(--gap-s) var(--gap-m);
}

.footer_highlight {
.footerHighlight {
border-top: 1px solid;
border-color: var(--color-static-quinary-dark);
}

.closer-wrapper {
.closerWrapper {
position: absolute;
top: 0;
right: 0;
Expand All @@ -132,11 +132,11 @@
transition: border-bottom 0.4s;
}

.modal_small .closer-wrapper {
.modalSmall .closerWrapper {
background: rgba(255, 255, 255, 0.95);
}

.closer-wrapper_highlight {
.closerWrapperHighlight {
border-bottom: 1px solid;
border-color: var(--color-static-quinary-dark);
}
Expand All @@ -160,7 +160,7 @@
}
}

.closer_small {
.closerSmall {
right: auto;
left: 0;
}
16 changes: 7 additions & 9 deletions packages/trap-focus/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export const TrapFocus: React.FC<TrapFocusProps> = props => {
const nodeToRestore = React.useRef<HTMLElement | null>();

const rootRef = React.useRef<HTMLElement | null>(null);
// can be removed once we drop support for non ref forwarding class components

// используется для non ref forwarding классовых компонентов
const handleOwnRef = React.useCallback(instance => {
rootRef.current = ReactDOM.findDOMNode(instance) as HTMLElement;
}, []);
Expand Down Expand Up @@ -142,11 +143,11 @@ export const TrapFocus: React.FC<TrapFocusProps> = props => {
return;
}

// Make sure the next tab starts from the right place.
// Чтобы табуляция всегда начиналась с нужной позиции.
if (doc.activeElement === rootRef.current) {
/*
* We need to ignore the next contain as
* it will try to move the focus back to the rootRef element.
* Необходимо игнорировать следующий контейнер, так как он
* будет пытаться сдвинуть фокус обратно на rootRef-элемент.
*/
ignoreNextEnforceFocus.current = true;
if (event.shiftKey) {
Expand Down Expand Up @@ -176,13 +177,10 @@ export const TrapFocus: React.FC<TrapFocusProps> = props => {
doc.removeEventListener('focus', contain, true);
doc.removeEventListener('keydown', loopFocus, true);

// restoreLastFocus()
if (!disableRestoreFocus) {
/*
* In IE 11 it is possible for document.activeElement to be null resulting
* in nodeToRestore.current being null.
* Not all elements in IE 11 have a focus method.
* Once IE 11 support is dropped the focus() call can be unconditional.
* В IE 11 document.activeElement может быть null -> nodeToRestore.current тоже будет null.
* Также не у всех элементов в IE 11 есть метод focus.
*/
if (nodeToRestore.current && nodeToRestore.current.focus) {
nodeToRestore.current.focus();
Expand Down

0 comments on commit 3c5c9e2

Please sign in to comment.