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
bf8cf270
Unverified
Commit
bf8cf270
authored
Feb 19, 2020
by
Robert Knight
Committed by
GitHub
Feb 19, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1806 from hypothesis/fix-button-pressed-state
Do not set "aria-pressed" attribute for non-toggle buttons
parents
8211e808
fd927d6b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
17 deletions
+34
-17
annotation-action-bar.js
src/sidebar/components/annotation-action-bar.js
+1
-1
button.js
src/sidebar/components/button.js
+16
-5
button-test.js
src/sidebar/components/test/button-test.js
+12
-6
top-bar-test.js
src/sidebar/components/test/top-bar-test.js
+2
-2
top-bar.js
src/sidebar/components/top-bar.js
+3
-3
No files found.
src/sidebar/components/annotation-action-bar.js
View file @
bf8cf270
...
...
@@ -96,7 +96,7 @@ function AnnotationActionBar({
)}
{
showFlagAction
&&
annotation
.
flagged
&&
(
<
Button
is
Active
=
{
true
}
is
Pressed
=
{
true
}
icon
=
"flag--active"
title
=
"Annotation has been reported to the moderators"
/>
...
...
src/sidebar/components/button.js
View file @
bf8cf270
...
...
@@ -21,7 +21,7 @@ export default function Button({
className
=
''
,
disabled
=
false
,
icon
=
''
,
is
Active
=
false
,
is
Pressed
,
onClick
=
()
=>
null
,
style
=
{},
title
,
...
...
@@ -35,6 +35,12 @@ export default function Button({
const
baseClassName
=
buttonText
?
'button--labeled'
:
'button--icon-only'
;
const
extraProps
=
{};
if
(
typeof
isPressed
===
'boolean'
)
{
// Indicate that this is a toggle button.
extraProps
[
'aria-pressed'
]
=
isPressed
;
}
return
(
<
button
className
=
{
classnames
(
...
...
@@ -44,15 +50,15 @@ export default function Button({
'button--compact'
:
useCompactStyle
,
'button--input'
:
useInputStyle
,
'button--primary'
:
usePrimaryStyle
,
'is-active'
:
is
Active
,
'is-active'
:
is
Pressed
,
},
className
)}
onClick
=
{
onClick
}
aria
-
pressed
=
{
isActive
}
title
=
{
title
}
style
=
{
style
}
disabled
=
{
disabled
}
{...
extraProps
}
>
{
icon
&&
<
SvgIcon
name
=
{
icon
}
className
=
"button__icon"
/>
}
{
buttonText
}
...
...
@@ -104,8 +110,13 @@ Button.propTypes = {
*/
icon
:
requiredStringIfButtonTextMissing
,
/** Is this button currently in an "active"/"on" state? */
isActive
:
propTypes
.
bool
,
/**
* Indicate that this is a toggle button (if `isPressed` is a boolean) and
* whether it is pressed.
*
* If omitted, the button is a non-toggle button.
*/
isPressed
:
propTypes
.
bool
,
/** callback for button clicks */
onClick
:
propTypes
.
func
,
...
...
src/sidebar/components/test/button-test.js
View file @
bf8cf270
...
...
@@ -14,7 +14,6 @@ describe('Button', () => {
return
mount
(
<
Button
icon
=
"fakeIcon"
isActive
=
{
false
}
title
=
"My Action"
onClick
=
{
fakeOnClick
}
{...
props
}
...
...
@@ -31,8 +30,8 @@ describe('Button', () => {
$imports
.
$restore
();
});
it
(
'adds active className if `is
Active
` is `true`'
,
()
=>
{
const
wrapper
=
createComponent
({
is
Active
:
true
});
it
(
'adds active className if `is
Pressed
` is `true`'
,
()
=>
{
const
wrapper
=
createComponent
({
is
Pressed
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
'is-active'
));
});
...
...
@@ -42,9 +41,16 @@ describe('Button', () => {
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
});
it
(
'sets ARIA `aria-pressed` attribute if `isActive`'
,
()
=>
{
const
wrapper
=
createComponent
({
isActive
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
prop
(
'aria-pressed'
));
[
true
,
false
].
forEach
(
isPressed
=>
{
it
(
'sets `aria-pressed` attribute if `isPressed` is a boolean'
,
()
=>
{
const
wrapper
=
createComponent
({
isPressed
});
assert
.
equal
(
wrapper
.
find
(
'button'
).
prop
(
'aria-pressed'
),
isPressed
);
});
});
it
(
'does not set `aria-pressed` attribute if `isPressed` is omitted'
,
()
=>
{
const
wrapper
=
createComponent
();
assert
.
notProperty
(
wrapper
.
find
(
'button'
).
props
(),
'aria-pressed'
);
});
it
(
'sets `title` to provided `title` prop'
,
()
=>
{
...
...
src/sidebar/components/test/top-bar-test.js
View file @
bf8cf270
...
...
@@ -119,7 +119,7 @@ describe('TopBar', () => {
wrapper
.
update
();
assert
.
isTrue
(
helpButton
.
props
().
is
Active
);
assert
.
isTrue
(
helpButton
.
props
().
is
Pressed
);
});
context
(
'help service handler configured in services'
,
()
=>
{
...
...
@@ -228,7 +228,7 @@ describe('TopBar', () => {
const
wrapper
=
createTopBar
();
const
shareButton
=
getButton
(
wrapper
,
'share'
);
assert
.
isTrue
(
shareButton
.
prop
(
'is
Active
'
));
assert
.
isTrue
(
shareButton
.
prop
(
'is
Pressed
'
));
});
it
(
'displays search input in the sidebar'
,
()
=>
{
...
...
src/sidebar/components/top-bar.js
View file @
bf8cf270
...
...
@@ -105,7 +105,7 @@ function TopBar({
<
Button
className
=
"top-bar__icon-button"
icon
=
"help"
is
Active
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
onClick
=
{
requestHelp
}
title
=
"Help"
useCompactStyle
...
...
@@ -135,7 +135,7 @@ function TopBar({
<
Button
className
=
"top-bar__icon-button"
icon
=
"share"
is
Active
=
{
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_SHARE_ANNOTATIONS
}
onClick
=
{
toggleSharePanel
}
...
...
@@ -146,7 +146,7 @@ function TopBar({
<
Button
className
=
"top-bar__icon-button"
icon
=
"help"
is
Active
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
onClick
=
{
requestHelp
}
title
=
"Help"
useCompactStyle
...
...
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