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({
...
@@ -96,7 +96,7 @@ function AnnotationActionBar({
)}
)}
{
showFlagAction
&&
annotation
.
flagged
&&
(
{
showFlagAction
&&
annotation
.
flagged
&&
(
<
Button
<
Button
is
Active
=
{
true
}
is
Pressed
=
{
true
}
icon
=
"flag--active"
icon
=
"flag--active"
title
=
"Annotation has been reported to the moderators"
title
=
"Annotation has been reported to the moderators"
/>
/>
...
...
src/sidebar/components/button.js
View file @
bf8cf270
...
@@ -21,7 +21,7 @@ export default function Button({
...
@@ -21,7 +21,7 @@ export default function Button({
className
=
''
,
className
=
''
,
disabled
=
false
,
disabled
=
false
,
icon
=
''
,
icon
=
''
,
is
Active
=
false
,
is
Pressed
,
onClick
=
()
=>
null
,
onClick
=
()
=>
null
,
style
=
{},
style
=
{},
title
,
title
,
...
@@ -35,6 +35,12 @@ export default function Button({
...
@@ -35,6 +35,12 @@ export default function Button({
const
baseClassName
=
buttonText
?
'button--labeled'
:
'button--icon-only'
;
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
(
return
(
<
button
<
button
className
=
{
classnames
(
className
=
{
classnames
(
...
@@ -44,15 +50,15 @@ export default function Button({
...
@@ -44,15 +50,15 @@ export default function Button({
'button--compact'
:
useCompactStyle
,
'button--compact'
:
useCompactStyle
,
'button--input'
:
useInputStyle
,
'button--input'
:
useInputStyle
,
'button--primary'
:
usePrimaryStyle
,
'button--primary'
:
usePrimaryStyle
,
'is-active'
:
is
Active
,
'is-active'
:
is
Pressed
,
},
},
className
className
)}
)}
onClick
=
{
onClick
}
onClick
=
{
onClick
}
aria
-
pressed
=
{
isActive
}
title
=
{
title
}
title
=
{
title
}
style
=
{
style
}
style
=
{
style
}
disabled
=
{
disabled
}
disabled
=
{
disabled
}
{...
extraProps
}
>
>
{
icon
&&
<
SvgIcon
name
=
{
icon
}
className
=
"button__icon"
/>
}
{
icon
&&
<
SvgIcon
name
=
{
icon
}
className
=
"button__icon"
/>
}
{
buttonText
}
{
buttonText
}
...
@@ -104,8 +110,13 @@ Button.propTypes = {
...
@@ -104,8 +110,13 @@ Button.propTypes = {
*/
*/
icon
:
requiredStringIfButtonTextMissing
,
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 */
/** callback for button clicks */
onClick
:
propTypes
.
func
,
onClick
:
propTypes
.
func
,
...
...
src/sidebar/components/test/button-test.js
View file @
bf8cf270
...
@@ -14,7 +14,6 @@ describe('Button', () => {
...
@@ -14,7 +14,6 @@ describe('Button', () => {
return
mount
(
return
mount
(
<
Button
<
Button
icon
=
"fakeIcon"
icon
=
"fakeIcon"
isActive
=
{
false
}
title
=
"My Action"
title
=
"My Action"
onClick
=
{
fakeOnClick
}
onClick
=
{
fakeOnClick
}
{...
props
}
{...
props
}
...
@@ -31,8 +30,8 @@ describe('Button', () => {
...
@@ -31,8 +30,8 @@ describe('Button', () => {
$imports
.
$restore
();
$imports
.
$restore
();
});
});
it
(
'adds active className if `is
Active
` is `true`'
,
()
=>
{
it
(
'adds active className if `is
Pressed
` is `true`'
,
()
=>
{
const
wrapper
=
createComponent
({
is
Active
:
true
});
const
wrapper
=
createComponent
({
is
Pressed
:
true
});
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
'is-active'
));
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
hasClass
(
'is-active'
));
});
});
...
@@ -42,9 +41,16 @@ describe('Button', () => {
...
@@ -42,9 +41,16 @@ describe('Button', () => {
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
assert
.
equal
(
wrapper
.
find
(
'SvgIcon'
).
prop
(
'name'
),
'fakeIcon'
);
});
});
it
(
'sets ARIA `aria-pressed` attribute if `isActive`'
,
()
=>
{
[
true
,
false
].
forEach
(
isPressed
=>
{
const
wrapper
=
createComponent
({
isActive
:
true
});
it
(
'sets `aria-pressed` attribute if `isPressed` is a boolean'
,
()
=>
{
assert
.
isTrue
(
wrapper
.
find
(
'button'
).
prop
(
'aria-pressed'
));
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'
,
()
=>
{
it
(
'sets `title` to provided `title` prop'
,
()
=>
{
...
...
src/sidebar/components/test/top-bar-test.js
View file @
bf8cf270
...
@@ -119,7 +119,7 @@ describe('TopBar', () => {
...
@@ -119,7 +119,7 @@ describe('TopBar', () => {
wrapper
.
update
();
wrapper
.
update
();
assert
.
isTrue
(
helpButton
.
props
().
is
Active
);
assert
.
isTrue
(
helpButton
.
props
().
is
Pressed
);
});
});
context
(
'help service handler configured in services'
,
()
=>
{
context
(
'help service handler configured in services'
,
()
=>
{
...
@@ -228,7 +228,7 @@ describe('TopBar', () => {
...
@@ -228,7 +228,7 @@ describe('TopBar', () => {
const
wrapper
=
createTopBar
();
const
wrapper
=
createTopBar
();
const
shareButton
=
getButton
(
wrapper
,
'share'
);
const
shareButton
=
getButton
(
wrapper
,
'share'
);
assert
.
isTrue
(
shareButton
.
prop
(
'is
Active
'
));
assert
.
isTrue
(
shareButton
.
prop
(
'is
Pressed
'
));
});
});
it
(
'displays search input in the sidebar'
,
()
=>
{
it
(
'displays search input in the sidebar'
,
()
=>
{
...
...
src/sidebar/components/top-bar.js
View file @
bf8cf270
...
@@ -105,7 +105,7 @@ function TopBar({
...
@@ -105,7 +105,7 @@ function TopBar({
<
Button
<
Button
className
=
"top-bar__icon-button"
className
=
"top-bar__icon-button"
icon
=
"help"
icon
=
"help"
is
Active
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
onClick
=
{
requestHelp
}
onClick
=
{
requestHelp
}
title
=
"Help"
title
=
"Help"
useCompactStyle
useCompactStyle
...
@@ -135,7 +135,7 @@ function TopBar({
...
@@ -135,7 +135,7 @@ function TopBar({
<
Button
<
Button
className
=
"top-bar__icon-button"
className
=
"top-bar__icon-button"
icon
=
"share"
icon
=
"share"
is
Active
=
{
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_SHARE_ANNOTATIONS
currentActivePanel
===
uiConstants
.
PANEL_SHARE_ANNOTATIONS
}
}
onClick
=
{
toggleSharePanel
}
onClick
=
{
toggleSharePanel
}
...
@@ -146,7 +146,7 @@ function TopBar({
...
@@ -146,7 +146,7 @@ function TopBar({
<
Button
<
Button
className
=
"top-bar__icon-button"
className
=
"top-bar__icon-button"
icon
=
"help"
icon
=
"help"
is
Active
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
is
Pressed
=
{
currentActivePanel
===
uiConstants
.
PANEL_HELP
}
onClick
=
{
requestHelp
}
onClick
=
{
requestHelp
}
title
=
"Help"
title
=
"Help"
useCompactStyle
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