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';
this.mounted = false;
}
- toggleFavorite = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
- event.preventDefault();
+ toggleFavorite = () => {
if (this.state.favorite) {
this.removeFavorite();
} else {
}
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>
);
}
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();
});
<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>
`;
<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>
`;
# FAVORITE
#
#------------------------------------------------------------------------------
+favorite.action.add=Add project to favorites
+favorite.action.remove=Remove project from favorites
favorite.check.TRK=Click to mark this project as favorite.
favorite.check.VW=Click to mark this portfolio as favorite.
favorite.check.SVW=Click to mark this sub-ortfolio as favorite.