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
02047ae4
Commit
02047ae4
authored
May 05, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `aria-expanded` to excerpt show/hide toggles
parent
a813d4e4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
9 deletions
+30
-9
annotation-body.js
src/sidebar/components/annotation-body.js
+3
-6
button.js
src/sidebar/components/button.js
+9
-0
excerpt.js
src/sidebar/components/excerpt.js
+2
-1
annotation-body-test.js
src/sidebar/components/test/annotation-body-test.js
+4
-2
button-test.js
src/sidebar/components/test/button-test.js
+12
-0
No files found.
src/sidebar/components/annotation-body.js
View file @
02047ae4
...
@@ -31,10 +31,6 @@ export default function AnnotationBody({
...
@@ -31,10 +31,6 @@ export default function AnnotationBody({
const
[
isCollapsible
,
setIsCollapsible
]
=
useState
(
false
);
const
[
isCollapsible
,
setIsCollapsible
]
=
useState
(
false
);
const
toggleText
=
isCollapsed
?
'More'
:
'Less'
;
const
toggleText
=
isCollapsed
?
'More'
:
'Less'
;
const
toggleTitle
=
isCollapsed
?
'Show full annotation text'
:
'Show the first few lines only'
;
const
showExcerpt
=
!
isEditing
&&
text
.
length
>
0
;
const
showExcerpt
=
!
isEditing
&&
text
.
length
>
0
;
const
showTagList
=
!
isEditing
&&
tags
.
length
>
0
;
const
showTagList
=
!
isEditing
&&
tags
.
length
>
0
;
...
@@ -69,10 +65,11 @@ export default function AnnotationBody({
...
@@ -69,10 +65,11 @@ export default function AnnotationBody({
{
isCollapsible
&&
!
isEditing
&&
(
{
isCollapsible
&&
!
isEditing
&&
(
<
div
className
=
"annotation-body__collapse-toggle"
>
<
div
className
=
"annotation-body__collapse-toggle"
>
<
Button
<
Button
buttonText
=
{
toggleText
}
className
=
"annotation-body__collapse-toggle-button"
className
=
"annotation-body__collapse-toggle-button"
isExpanded
=
{
!
isCollapsed
}
onClick
=
{()
=>
setIsCollapsed
(
!
isCollapsed
)}
onClick
=
{()
=>
setIsCollapsed
(
!
isCollapsed
)}
buttonText
=
{
toggleText
}
title
=
"Toggle to show full annotation text"
title
=
{
toggleTitle
}
/>
/>
<
/div
>
<
/div
>
)}
)}
...
...
src/sidebar/components/button.js
View file @
02047ae4
...
@@ -21,6 +21,7 @@ export default function Button({
...
@@ -21,6 +21,7 @@ export default function Button({
className
=
''
,
className
=
''
,
disabled
=
false
,
disabled
=
false
,
icon
=
''
,
icon
=
''
,
isExpanded
,
isPressed
,
isPressed
,
onClick
=
()
=>
null
,
onClick
=
()
=>
null
,
style
=
{},
style
=
{},
...
@@ -40,6 +41,9 @@ export default function Button({
...
@@ -40,6 +41,9 @@ export default function Button({
// Indicate that this is a toggle button.
// Indicate that this is a toggle button.
extraProps
[
'aria-pressed'
]
=
isPressed
;
extraProps
[
'aria-pressed'
]
=
isPressed
;
}
}
if
(
typeof
isExpanded
===
'boolean'
)
{
extraProps
[
'aria-expanded'
]
=
isExpanded
;
}
return
(
return
(
<
button
<
button
...
@@ -110,6 +114,11 @@ Button.propTypes = {
...
@@ -110,6 +114,11 @@ Button.propTypes = {
*/
*/
icon
:
requiredStringIfButtonTextMissing
,
icon
:
requiredStringIfButtonTextMissing
,
/**
* Is the expandable element controlled by this button currently expanded?
*/
isExpanded
:
propTypes
.
bool
,
/**
/**
* Indicate that this is a toggle button (if `isPressed` is a boolean) and
* Indicate that this is a toggle button (if `isPressed` is a boolean) and
* whether it is pressed.
* whether it is pressed.
...
...
src/sidebar/components/excerpt.js
View file @
02047ae4
...
@@ -20,7 +20,8 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
...
@@ -20,7 +20,8 @@ function InlineControls({ isCollapsed, setCollapsed, linkStyle = {} }) {
<
button
<
button
className
=
"excerpt__toggle-button"
className
=
"excerpt__toggle-button"
onClick
=
{()
=>
setCollapsed
(
!
isCollapsed
)}
onClick
=
{()
=>
setCollapsed
(
!
isCollapsed
)}
aria
-
label
=
"Toggle to show the full excerpt or first few lines only"
aria
-
expanded
=
{
!
isCollapsed
}
aria
-
label
=
"Toggle to show the full excerpt"
aria
-
pressed
=
{(
!
isCollapsed
).
toString
()}
aria
-
pressed
=
{(
!
isCollapsed
).
toString
()}
style
=
{
linkStyle
}
style
=
{
linkStyle
}
>
>
...
...
src/sidebar/components/test/annotation-body-test.js
View file @
02047ae4
...
@@ -65,7 +65,8 @@ describe('AnnotationBody', () => {
...
@@ -65,7 +65,8 @@ describe('AnnotationBody', () => {
const
button
=
wrapper
.
find
(
'Button'
);
const
button
=
wrapper
.
find
(
'Button'
);
assert
.
isOk
(
button
.
exists
());
assert
.
isOk
(
button
.
exists
());
assert
.
equal
(
button
.
props
().
buttonText
,
'More'
);
assert
.
equal
(
button
.
props
().
buttonText
,
'More'
);
assert
.
equal
(
button
.
props
().
title
,
'Show full annotation text'
);
assert
.
equal
(
button
.
props
().
title
,
'Toggle to show full annotation text'
);
assert
.
isFalse
(
button
.
props
().
isExpanded
);
});
});
it
(
'shows appropriate button text to collapse the Excerpt if expanded'
,
()
=>
{
it
(
'shows appropriate button text to collapse the Excerpt if expanded'
,
()
=>
{
...
@@ -87,7 +88,8 @@ describe('AnnotationBody', () => {
...
@@ -87,7 +88,8 @@ describe('AnnotationBody', () => {
const
buttonProps
=
wrapper
.
find
(
'Button'
).
props
();
const
buttonProps
=
wrapper
.
find
(
'Button'
).
props
();
assert
.
equal
(
buttonProps
.
buttonText
,
'Less'
);
assert
.
equal
(
buttonProps
.
buttonText
,
'Less'
);
assert
.
equal
(
buttonProps
.
title
,
'Show the first few lines only'
);
assert
.
equal
(
buttonProps
.
title
,
'Toggle to show full annotation text'
);
assert
.
isTrue
(
buttonProps
.
isExpanded
);
});
});
describe
(
'tag list and editor'
,
()
=>
{
describe
(
'tag list and editor'
,
()
=>
{
...
...
src/sidebar/components/test/button-test.js
View file @
02047ae4
...
@@ -41,6 +41,18 @@ describe('Button', () => {
...
@@ -41,6 +41,18 @@ describe('Button', () => {
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
});
});
[
true
,
false
].
forEach
(
isExpanded
=>
{
it
(
'sets `aria-expanded` attribute if `isExpanded` is a boolean'
,
()
=>
{
const
wrapper
=
createComponent
({
isExpanded
});
assert
.
equal
(
wrapper
.
find
(
'button'
).
prop
(
'aria-expanded'
),
isExpanded
);
});
});
it
(
'does not set `aria-expanded` attribute if `isExpanded` is omitted'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
notProperty
(
wrapper
.
find
(
'button'
).
props
(),
'aria-expanded'
);
});
[
true
,
false
].
forEach
(
isPressed
=>
{
[
true
,
false
].
forEach
(
isPressed
=>
{
it
(
'sets `aria-pressed` attribute if `isPressed` is a boolean'
,
()
=>
{
it
(
'sets `aria-pressed` attribute if `isPressed` is a boolean'
,
()
=>
{
const
wrapper
=
createComponent
({
isPressed
});
const
wrapper
=
createComponent
({
isPressed
});
...
...
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