Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
5f369a0b
Commit
5f369a0b
authored
Mar 31, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Apr 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure sidebar panels are focused when open, and focus is restored when closed
parent
1b476206
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
SidebarPanel.tsx
src/sidebar/components/SidebarPanel.tsx
+16
-10
Slider.tsx
src/sidebar/components/Slider.tsx
+12
-3
No files found.
src/sidebar/components/SidebarPanel.tsx
View file @
5f369a0b
import
{
Panel
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
{
Dialog
}
from
'@hypothesis/frontend-shared/lib/next'
;
import
type
{
IconComponent
}
from
'@hypothesis/frontend-shared/lib/types'
;
import
type
{
ComponentChildren
}
from
'preact'
;
import
{
useCallback
,
useEffect
,
useRef
}
from
'preact/hooks'
;
...
...
@@ -47,9 +47,7 @@ export default function SidebarPanel({
if
(
panelIsActive
&&
panelElement
.
current
)
{
scrollIntoView
(
panelElement
.
current
);
}
if
(
typeof
onActiveChanged
===
'function'
)
{
onActiveChanged
(
panelIsActive
);
}
onActiveChanged
?.(
panelIsActive
);
}
},
[
panelIsActive
,
onActiveChanged
]);
...
...
@@ -58,12 +56,20 @@ export default function SidebarPanel({
},
[
store
,
panelName
]);
return
(
<
Slider
visible=
{
panelIsActive
}
>
<
div
ref=
{
panelElement
}
className=
"mb-4"
>
<
Panel
title=
{
title
}
icon=
{
icon
}
onClose=
{
closePanel
}
>
<>
{
panelIsActive
&&
(
<
Dialog
restoreFocus
ref=
{
panelElement
}
classes=
"mb-4"
title=
{
title
}
icon=
{
icon
}
onClose=
{
closePanel
}
transitionComponent=
{
Slider
}
>
{
children
}
</
Panel
>
</
div
>
</
Slider
>
</
Dialog
>
)
}
</>
);
}
src/sidebar/components/Slider.tsx
View file @
5f369a0b
...
...
@@ -7,6 +7,9 @@ export type SliderProps = {
/** Whether the content should be visible or not. */
visible
:
boolean
;
/** Invoked once the open/close transitions have finished */
onTransitionEnd
?:
(
direction
:
'in'
|
'out'
)
=>
void
;
};
/**
...
...
@@ -17,9 +20,13 @@ export type SliderProps = {
* DOM using `display: none` so it does not appear in the keyboard navigation
* order.
*
* Currently the only reveal/expand direction supported is top-down.
* Currently
,
the only reveal/expand direction supported is top-down.
*/
export
default
function
Slider
({
children
,
visible
}:
SliderProps
)
{
export
default
function
Slider
({
children
,
visible
,
onTransitionEnd
,
}:
SliderProps
)
{
const
containerRef
=
useRef
<
HTMLDivElement
|
null
>
(
null
);
const
[
containerHeight
,
setContainerHeight
]
=
useState
(
visible
?
'auto'
:
0
);
...
...
@@ -68,13 +75,15 @@ export default function Slider({ children, visible }: SliderProps) {
const
handleTransitionEnd
=
useCallback
(()
=>
{
if
(
visible
)
{
setContainerHeight
(
'auto'
);
onTransitionEnd
?.(
'in'
);
}
else
{
// When the collapse animation completes, stop rendering the content so
// that the browser has fewer nodes to render and the content is removed
// from keyboard navigation.
setContentVisible
(
false
);
onTransitionEnd
?.(
'out'
);
}
},
[
setContainerHeight
,
visible
]);
},
[
setContainerHeight
,
visible
,
onTransitionEnd
]);
const
isFullyVisible
=
containerHeight
===
'auto'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment