Skip to content

Commit

Permalink
Merge pull request #471 from sebgroup/develop
Browse files Browse the repository at this point in the history
Release: Modal undefined error fixes
  • Loading branch information
DanSallau authored Sep 22, 2020
2 parents 6824d06 + fe63d4c commit 3a9696d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ModalProps {
}

export const Modal: React.FC<ModalProps> = React.memo(({ trapFocus = true, escapeToDismiss = true, ...props }: ModalProps) => {
const prestine: React.MutableRefObject<boolean> = React.useRef<boolean>(true);
const pristine: React.MutableRefObject<boolean> = React.useRef<boolean>(true);
const [className, setClassName] = React.useState<string>("seb modal");
const modalRef: React.MutableRefObject<HTMLDivElement> = React.useRef<HTMLDivElement>();
/**
Expand Down Expand Up @@ -83,7 +83,9 @@ export const Modal: React.FC<ModalProps> = React.memo(({ trapFocus = true, escap
focusableElement && focusableElement.focus();
}
/** Un-focus from the element inside the modal when it's toggled off */
!props.toggle && (document.activeElement as HTMLElement).blur();
if (!props.toggle && pristine.current && trapFocus) {
(document.activeElement as HTMLElement)?.blur();
}

return () => {
window.removeEventListener("keydown", keyCombinationListener);
Expand Down Expand Up @@ -118,7 +120,7 @@ export const Modal: React.FC<ModalProps> = React.memo(({ trapFocus = true, escap

React.useEffect(() => {
let classNames: string = "seb modal";
classNames += props.toggle ? " show" : prestine.current ? "" : " hide";
classNames += props.toggle ? " show" : pristine.current ? "" : " hide";
classNames += props.centered ? " modal-centered" : "";
classNames += !!props.position ? " modal-aside modal-aside-" + (props.position === "left" ? "left" : "right") : "";
classNames += props.fullscreen ? " modal-fullscreen" : "";
Expand All @@ -127,7 +129,7 @@ export const Modal: React.FC<ModalProps> = React.memo(({ trapFocus = true, escap
}, [props.toggle, props.centered, props.position, props.fullscreen, props.className]);

React.useEffect(() => {
prestine.current = false;
pristine.current = false;

escapeToDismiss && window[props.toggle ? "addEventListener" : "removeEventListener"]("keyup", escapeKeyListener);
return () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Table/table-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ table {
> .ellipsis-dropdown-holder {
position: relative;
display: inline-block;

min-width: 20px;
.icon-holder {
&:hover {
background: $icon-active-color;
Expand Down

0 comments on commit 3a9696d

Please sign in to comment.