-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Desktop: Improve focus handling for notebook edit, share, and sync dialogs #10779
Merged
laurent22
merged 2 commits into
laurent22:dev
from
personalizedrefrigerator:pr/desktop/improve-dialog-accessibility
Jul 26, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
import styled from 'styled-components'; | ||
|
||
const DialogModalLayer = styled.div` | ||
z-index: 9999; | ||
display: flex; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0,0,0,0.6); | ||
align-items: flex-start; | ||
justify-content: center; | ||
|
||
overflow: auto; | ||
scrollbar-width: none; | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
const DialogRoot = styled.div` | ||
background-color: ${props => props.theme.backgroundColor}; | ||
padding: 16px; | ||
box-shadow: 6px 6px 20px rgba(0,0,0,0.5); | ||
margin: 20px; | ||
min-height: fit-content; | ||
display: flex; | ||
flex-direction: column; | ||
border-radius: 10px; | ||
`; | ||
import * as React from 'react'; | ||
import { ReactElement, ReactEventHandler, useCallback, useEffect, useRef, useState } from 'react'; | ||
|
||
interface Props { | ||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied | ||
renderContent: Function; | ||
renderContent: ()=> ReactElement; | ||
className?: string; | ||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied | ||
onClose?: Function; | ||
onClose?: ()=> void; | ||
} | ||
|
||
export default function Dialog(props: Props) { | ||
const [dialogElement, setDialogRef] = useState<HTMLDialogElement>(); | ||
|
||
useEffect(() => { | ||
if (!dialogElement) return; | ||
|
||
// Use .showModal instead of the open attribute: .showModal correctly | ||
// traps the keyboard focus in the dialog | ||
dialogElement.showModal(); | ||
}, [dialogElement]); | ||
|
||
const onCloseRef = useRef(props.onClose); | ||
onCloseRef.current = props.onClose; | ||
|
||
const onCancel: ReactEventHandler<HTMLDialogElement> = useCallback((event) => { | ||
const canCancel = !!onCloseRef.current; | ||
if (canCancel) { | ||
// Prevents [Escape] from closing the dialog. In many places, this is handled | ||
// elsewhere. | ||
// See https://stackoverflow.com/a/61021326 | ||
event.preventDefault(); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<DialogModalLayer className={props.className}> | ||
<DialogRoot> | ||
<dialog | ||
ref={setDialogRef} | ||
className={`dialog-modal-layer ${props.className}`} | ||
onClose={props.onClose} | ||
onCancel={onCancel} | ||
> | ||
<div className='content'> | ||
{props.renderContent()} | ||
</DialogRoot> | ||
</DialogModalLayer> | ||
</div> | ||
</dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
.dialog-modal-layer { | ||
display: flex; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
align-items: flex-start; | ||
justify-content: center; | ||
border: none; | ||
margin: 0; | ||
background-color: transparent; | ||
|
||
> .content { | ||
background-color: var(--joplin-background-color); | ||
padding: 16px; | ||
box-shadow: 6px 6px 20px rgba(0,0,0,0.5); | ||
margin: 20px; | ||
min-height: fit-content; | ||
display: flex; | ||
flex-direction: column; | ||
border-radius: 10px; | ||
} | ||
|
||
&::backdrop { | ||
background-color: rgba(0,0,0,0.6); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
@use './dialog-modal-layer.scss'; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSCSS specifies that one top-level rule should be in each file. I've created a new
styles/
folder to satisfy this rule. Note, however, that a style/ folder already exists, and contains styled component logic. As such, it might make sense to movestyles/dialog-modal-layer.scss
to a different location.Additionally, RSCSS states that glob matching should be used. However, Dart SCSS does not seem to support globs in
@use
or@import
.