Skip to content

Commit

Permalink
Standard fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
karleinarb committed Mar 30, 2022
1 parent 1812eb5 commit bdb6939
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
13 changes: 5 additions & 8 deletions src/ui/Dialog/Dialog.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ export function Nested () {

return (
<>
<p>

</p>
<p />
<Button onClick={() => { setIsDialogOpen(!dialogOpen) }}>{`${!dialogOpen ? 'Åpne' : 'Lukk'} modal`}</Button>
<Dialog
isOpen={dialogOpen}

onDismiss={() => { setIsDialogOpen(false) }}
showCloseButton
width="60%"
height="50%"
width='60%'
height='50%'
>
<DialogTitle>This is the first dialog</DialogTitle>
<DialogBody>
Expand All @@ -100,8 +97,8 @@ export function Nested () {
<Dialog
isOpen={dialog2Open}
onDismiss={() => setDialog2Open(false)}
width="50%"
height="30%"
width='50%'
height='30%'
>
<DialogTitle>
This is the second nested dialog
Expand Down
18 changes: 9 additions & 9 deletions src/ui/Dialog/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'
import PropTypes from 'prop-types'
import { nanoid } from 'nanoid'

Expand All @@ -23,14 +23,14 @@ export function Dialog ({ isOpen, title, className, persistent, width, height, s
console.log('Key', e)
if (e.code === 'Escape' && isOpen) {
// Determine if this is the active dialog
const dialogs = document.getElementsByClassName('dialog');
const dialogs = document.getElementsByClassName('dialog')

let isActiveDialog = false;
if(!dialogs || dialogs.length <= 1) isActiveDialog = true;
else if(dialogs[dialogs.length - 1].id === `dialog-${id}`) isActiveDialog = true;
let isActiveDialog = false
if (!dialogs || dialogs.length <= 1) isActiveDialog = true
else if (dialogs[dialogs.length - 1].id === `dialog-${id}`) isActiveDialog = true

// If it is, run actions
if(isActiveDialog) {
if (isActiveDialog) {
if (persistent && !onPressEscape) shakeDialogBox()
else if (onPressEscape && typeof onPressEscape === 'function') onPressEscape()
else if (onDismiss && typeof onDismiss === 'function') onDismiss()
Expand All @@ -44,7 +44,7 @@ export function Dialog ({ isOpen, title, className, persistent, width, height, s
document.removeEventListener('keydown', handleKeyDown)
}
})

// Plays the shaking animation-effect when the dialog is persistent
function shakeDialogBox () {
const dialog = document.getElementById(`dialog-${id}`)
Expand All @@ -57,7 +57,7 @@ export function Dialog ({ isOpen, title, className, persistent, width, height, s
dialog.addEventListener('animationend', animationEndCallback)
}

function handleBackdropClick(e) {
function handleBackdropClick (e) {
const clickedBackdrop = e.target.id === `dialog-backdrop-${id}`

if (isOpen && clickedBackdrop) {
Expand All @@ -79,7 +79,7 @@ export function Dialog ({ isOpen, title, className, persistent, width, height, s
<div id={`dialog-backdrop-${id}`} className={`dialog-backdrop ${className}`} onClick={(e) => handleBackdropClick(e)}>
<div id={`dialog-${id}`} className='dialog' aria-label='dialog' aria-modal='true' role='dialog' style={parsedStyles}>
{!persistent && showCloseButton &&
<button className='dialog-close-btn' onClick={(e) => { handleCloseBtnClick(); e.preventDefault(); }} aria-label='Lukk'>
<button className='dialog-close-btn' onClick={(e) => { handleCloseBtnClick(); e.preventDefault() }} aria-label='Lukk'>
<CloseIcon alt='' />
</button>}
{props.children}
Expand Down

1 comment on commit bdb6939

@vercel
Copy link

@vercel vercel bot commented on bdb6939 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.