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
57c4cc11
Commit
57c4cc11
authored
Jul 23, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jul 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace useElementShouldClose with usePopoverShouldClose
parent
b57fc1f9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
12 deletions
+28
-12
AnnotationShareControl.tsx
src/sidebar/components/Annotation/AnnotationShareControl.tsx
+4
-4
AnnotationShareControl-test.js
...components/Annotation/test/AnnotationShareControl-test.js
+1
-1
Menu.tsx
src/sidebar/components/Menu.tsx
+2
-2
TagEditor.tsx
src/sidebar/components/TagEditor.tsx
+3
-3
Menu-test.js
src/sidebar/components/test/Menu-test.js
+14
-1
TagEditor-test.js
src/sidebar/components/test/TagEditor-test.js
+4
-1
No files found.
src/sidebar/components/Annotation/AnnotationShareControl.tsx
View file @
57c4cc11
import
{
use
Element
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
use
Popover
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
Card
,
IconButton
,
...
...
@@ -62,8 +62,8 @@ function AnnotationShareControl({
const
toggleSharePanel
=
()
=>
setOpen
(
!
isOpen
);
const
closePanel
=
()
=>
setOpen
(
false
);
// Interactions outside
of
the component when it is open should close it
use
ElementShouldClose
(
shareRef
,
isOpen
,
closePanel
);
// Interactions outside the component when it is open should close it
use
PopoverShouldClose
(
shareRef
,
closePanel
,
{
enabled
:
isOpen
}
);
useEffect
(()
=>
{
if
(
wasOpen
.
current
!==
isOpen
)
{
...
...
@@ -130,7 +130,7 @@ function AnnotationShareControl({
// Make the container div focusable by setting a non-null `tabIndex`.
// This prevents clicks on non-focusable contents from "leaking out" and
// focusing a focusable ancester. If something outside of the panel gains
// focus, `use
Element
ShouldClose`'s focus listener will close the panel.
// focus, `use
Popover
ShouldClose`'s focus listener will close the panel.
// "Catch focus" here to prevent this.
// See https://github.com/hypothesis/client/issues/5196
<
div
className=
"relative"
ref=
{
shareRef
}
tabIndex=
{
-
1
}
>
...
...
src/sidebar/components/Annotation/test/AnnotationShareControl-test.js
View file @
57c4cc11
...
...
@@ -88,7 +88,7 @@ describe('AnnotationShareControl', () => {
$imports
.
$mock
(
mockImportedComponents
());
$imports
.
$mock
({
'@hypothesis/frontend-shared'
:
{
use
Element
ShouldClose
:
sinon
.
stub
(),
use
Popover
ShouldClose
:
sinon
.
stub
(),
},
'../../helpers/annotation-sharing'
:
{
isShareableURI
:
fakeIsShareableURI
,
...
...
src/sidebar/components/Menu.tsx
View file @
57c4cc11
import
{
use
Element
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
use
Popover
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
MenuExpandIcon
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
type
{
ComponentChildren
}
from
'preact'
;
...
...
@@ -145,7 +145,7 @@ export default function Menu({
// Menu element should close via `closeMenu` whenever it's open and there
// are user interactions outside of it (e.g. clicks) in the document
use
ElementShouldClose
(
menuRef
,
isOpen
,
closeMenu
);
use
PopoverShouldClose
(
menuRef
,
closeMenu
,
{
enabled
:
isOpen
}
);
const
stopPropagation
=
(
e
:
Event
)
=>
e
.
stopPropagation
();
...
...
src/sidebar/components/TagEditor.tsx
View file @
57c4cc11
import
{
use
Element
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
use
Popover
ShouldClose
}
from
'@hypothesis/frontend-shared'
;
import
{
Input
}
from
'@hypothesis/frontend-shared'
;
import
classnames
from
'classnames'
;
import
{
useRef
,
useState
}
from
'preact/hooks'
;
...
...
@@ -45,8 +45,8 @@ function TagEditor({
// Set up callback to monitor outside click events to close the AutocompleteList
const
closeWrapperRef
=
useRef
<
HTMLDivElement
>
(
null
);
use
ElementShouldClose
(
closeWrapperRef
,
suggestionsListOpen
,
()
=>
{
setSuggestionsListOpen
(
false
);
use
PopoverShouldClose
(
closeWrapperRef
,
()
=>
setSuggestionsListOpen
(
false
),
{
enabled
:
suggestionsListOpen
,
});
/**
...
...
src/sidebar/components/test/Menu-test.js
View file @
57c4cc11
...
...
@@ -112,7 +112,6 @@ describe('Menu', () => {
new
Event
(
'mousedown'
),
new
Event
(
'click'
),
((
e
=
new
Event
(
'keydown'
)),
(
e
.
key
=
'Escape'
),
e
),
new
Event
(
'focus'
),
].
forEach
(
event
=>
{
it
(
`closes when the user clicks or presses the mouse outside (
${
event
.
type
}
)`
,
()
=>
{
const
wrapper
=
createMenu
({
defaultOpen
:
true
});
...
...
@@ -126,6 +125,20 @@ describe('Menu', () => {
});
});
it
(
'closes when menu loses focus'
,
()
=>
{
const
wrapper
=
createMenu
({
defaultOpen
:
true
});
act
(()
=>
{
wrapper
.
find
(
menuSelector
)
.
getDOMNode
()
.
dispatchEvent
(
new
Event
(
'focusout'
));
});
wrapper
.
update
();
assert
.
isFalse
(
isOpen
(
wrapper
));
});
it
(
'does not close when user presses non-Escape key outside'
,
()
=>
{
const
wrapper
=
createMenu
({
defaultOpen
:
true
});
...
...
src/sidebar/components/test/TagEditor-test.js
View file @
57c4cc11
...
...
@@ -224,7 +224,10 @@ describe('TagEditor', () => {
wrapper
.
find
(
'input'
).
instance
().
value
=
'non-empty'
;
typeInput
(
wrapper
);
assert
.
equal
(
wrapper
.
find
(
'AutocompleteList'
).
prop
(
'open'
),
true
);
document
.
body
.
dispatchEvent
(
new
Event
(
'focus'
));
wrapper
.
find
(
'[data-testid="combobox-container"]'
)
.
getDOMNode
()
.
dispatchEvent
(
new
Event
(
'focusout'
));
wrapper
.
update
();
assert
.
equal
(
wrapper
.
find
(
'AutocompleteList'
).
prop
(
'open'
),
false
);
});
...
...
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