aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/components/controls
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2019-06-19 09:48:56 +0200
committersonartech <sonartech@sonarsource.com>2019-06-28 08:45:41 +0200
commit41c1327463c9c7bf2df7f272ddf83b524e6d9007 (patch)
tree75e55a5e817f01934deb47c4d2bfc2417d3eaaf9 /server/sonar-web/src/main/js/components/controls
parenta011c5f350cc8f27940ef71a55b49a41f1bac7f8 (diff)
downloadsonarqube-41c1327463c9c7bf2df7f272ddf83b524e6d9007.tar.gz
sonarqube-41c1327463c9c7bf2df7f272ddf83b524e6d9007.zip
SONAR-11685 Make 'Add to favorites' link more accessible
Diffstat (limited to 'server/sonar-web/src/main/js/components/controls')
-rw-r--r--server/sonar-web/src/main/js/components/controls/FavoriteBase.tsx18
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/FavoriteBase-test.tsx.snap16
3 files changed, 20 insertions, 18 deletions
diff --git a/server/sonar-web/src/main/js/components/controls/FavoriteBase.tsx b/server/sonar-web/src/main/js/components/controls/FavoriteBase.tsx
index 10865ee16c7..45a812d5425 100644
--- a/server/sonar-web/src/main/js/components/controls/FavoriteBase.tsx
+++ b/server/sonar-web/src/main/js/components/controls/FavoriteBase.tsx
@@ -20,6 +20,7 @@
import * as React from 'react';
import * as classNames from 'classnames';
import Tooltip from './Tooltip';
+import { ButtonLink } from '../ui/buttons';
import FavoriteIcon from '../icons-components/FavoriteIcon';
import { translate } from '../../helpers/l10n';
@@ -51,8 +52,7 @@ export default class FavoriteBase extends React.PureComponent<Props, State> {
this.mounted = false;
}
- toggleFavorite = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
+ toggleFavorite = () => {
if (this.state.favorite) {
this.removeFavorite();
} else {
@@ -83,17 +83,19 @@ export default class FavoriteBase extends React.PureComponent<Props, State> {
}
render() {
- const tooltip = this.state.favorite
+ const { favorite } = this.state;
+ const tooltip = favorite
? translate('favorite.current', this.props.qualifier)
: translate('favorite.check', this.props.qualifier);
+ const ariaLabel = translate('favorite.action', favorite ? 'remove' : 'add');
return (
<Tooltip overlay={tooltip}>
- <a
- className={classNames('display-inline-block', 'link-no-underline', this.props.className)}
- href="#"
+ <ButtonLink
+ aria-label={ariaLabel}
+ className={classNames('favorite-link', 'link-no-underline', this.props.className)}
onClick={this.toggleFavorite}>
- <FavoriteIcon favorite={this.state.favorite} />
- </a>
+ <FavoriteIcon favorite={favorite} />
+ </ButtonLink>
</Tooltip>
);
}
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.tsx
index 58041c11898..7368291c8c7 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/FavoriteBase-test.tsx
@@ -35,14 +35,14 @@ it('should render not favorite', () => {
it('should add favorite', () => {
const addFavorite = jest.fn(() => Promise.resolve());
const favorite = renderFavoriteBase({ favorite: false, addFavorite });
- click(favorite.find('a'));
+ click(favorite.find('ButtonLink'));
expect(addFavorite).toBeCalled();
});
it('should remove favorite', () => {
const removeFavorite = jest.fn(() => Promise.resolve());
const favorite = renderFavoriteBase({ favorite: true, removeFavorite });
- click(favorite.find('a'));
+ click(favorite.find('ButtonLink'));
expect(removeFavorite).toBeCalled();
});
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/FavoriteBase-test.tsx.snap b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/FavoriteBase-test.tsx.snap
index f24dedb7531..22815684de0 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/FavoriteBase-test.tsx.snap
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/FavoriteBase-test.tsx.snap
@@ -4,15 +4,15 @@ exports[`should render favorite 1`] = `
<Tooltip
overlay="favorite.current.TRK"
>
- <a
- className="display-inline-block link-no-underline"
- href="#"
+ <ButtonLink
+ aria-label="favorite.action.remove"
+ className="favorite-link link-no-underline"
onClick={[Function]}
>
<FavoriteIcon
favorite={true}
/>
- </a>
+ </ButtonLink>
</Tooltip>
`;
@@ -20,14 +20,14 @@ exports[`should render not favorite 1`] = `
<Tooltip
overlay="favorite.check.TRK"
>
- <a
- className="display-inline-block link-no-underline"
- href="#"
+ <ButtonLink
+ aria-label="favorite.action.add"
+ className="favorite-link link-no-underline"
onClick={[Function]}
>
<FavoriteIcon
favorite={false}
/>
- </a>
+ </ButtonLink>
</Tooltip>
`;