Skip to content

Commit 65e033d

Browse files
authored
fix(MessageViewButton): adjust default tooltip (#7162)
1 parent ee114c5 commit 65e033d

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

packages/main/src/components/MessageViewButton/MessageViewButton.cy.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import ValueState from '@ui5/webcomponents-base/dist/types/ValueState.js';
22
import { MessageViewButton } from './index.js';
33

4+
const testCases: [ValueState | undefined, string, string, string][] = [
5+
[ValueState.Negative, 'error', 'Error Type', 'Error'],
6+
[ValueState.Positive, 'sys-enter-2', 'Success Type', 'Success'],
7+
[ValueState.Critical, 'alert', 'Warning Type', 'Warning'],
8+
[ValueState.Information, 'information', 'Information Type', 'Information'],
9+
[ValueState.None, 'information', 'Information Type', 'Information'],
10+
[undefined, 'error', 'Error Type', 'Error']
11+
];
12+
413
describe('MessageViewButton', () => {
5-
[
6-
[ValueState.Negative, 'error'],
7-
[ValueState.Positive, 'sys-enter-2'],
8-
[ValueState.Critical, 'alert'],
9-
[ValueState.Information, 'information'],
10-
[ValueState.None, 'information'],
11-
[undefined, 'error']
12-
].forEach(([type, icon]: [ValueState, string]) => {
14+
testCases.forEach(([type, icon, label, tooltip]) => {
1315
it(`type ${type}`, () => {
1416
cy.mount(<MessageViewButton type={type} data-testid={type ?? 'undefined'} />);
1517
cy.findByTestId(type ?? 'undefined')
1618
.should('have.attr', 'icon', icon)
17-
.should('be.visible');
19+
.and('have.attr', 'accessible-name', label)
20+
.and('have.attr', 'tooltip', tooltip)
21+
.and('be.visible');
1822
});
1923
});
2024
it('counter', () => {

packages/main/src/components/MessageViewButton/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ import sysEnter2Icon from '@ui5/webcomponents-icons/dist/sys-enter-2.js';
88
import { useI18nBundle, useStylesheet } from '@ui5/webcomponents-react-base';
99
import { clsx } from 'clsx';
1010
import { forwardRef } from 'react';
11-
import { ERROR_TYPE, WARNING_TYPE, INFORMATION_TYPE, SUCCESS_TYPE } from '../../i18n/i18n-defaults.js';
11+
import {
12+
ERROR_TYPE,
13+
WARNING_TYPE,
14+
INFORMATION_TYPE,
15+
SUCCESS_TYPE,
16+
ERROR,
17+
SUCCESS,
18+
WARNING,
19+
INFORMATION
20+
} from '../../i18n/i18n-defaults.js';
1221
import type { ButtonDomRef, ButtonPropTypes } from '../../webComponents/index.js';
1322
import { Button } from '../../webComponents/index.js';
1423
import { classNames, styleData } from './MessageViewButton.module.css.js';
@@ -32,18 +41,19 @@ export interface MessageViewButtonProptypes
3241
interface Types {
3342
icon: string;
3443
i18nLabel: { key: string; defaultText: string };
44+
tooltip: { key: string; defaultText: string };
3545
}
3646

3747
const getTypes = (type: MessageViewButtonProptypes['type']): Types => {
3848
switch (type) {
3949
case ValueState.Negative:
40-
return { icon: errorIcon, i18nLabel: ERROR_TYPE };
50+
return { icon: errorIcon, i18nLabel: ERROR_TYPE, tooltip: ERROR };
4151
case ValueState.Positive:
42-
return { icon: sysEnter2Icon, i18nLabel: SUCCESS_TYPE };
52+
return { icon: sysEnter2Icon, i18nLabel: SUCCESS_TYPE, tooltip: SUCCESS };
4353
case ValueState.Critical:
44-
return { icon: alertIcon, i18nLabel: WARNING_TYPE };
54+
return { icon: alertIcon, i18nLabel: WARNING_TYPE, tooltip: WARNING };
4555
default:
46-
return { icon: informationIcon, i18nLabel: INFORMATION_TYPE };
56+
return { icon: informationIcon, i18nLabel: INFORMATION_TYPE, tooltip: INFORMATION };
4757
}
4858
};
4959

@@ -54,7 +64,7 @@ const MessageViewButton = forwardRef<ButtonDomRef, MessageViewButtonProptypes>((
5464
const { type = ValueState.Negative, counter, className, tooltip, accessibleName, ...rest } = props;
5565
useStylesheet(styleData, MessageViewButton.displayName);
5666
const classes = clsx(classNames.btn, className);
57-
const { icon, i18nLabel } = getTypes(type);
67+
const { icon, i18nLabel, tooltip: title } = getTypes(type);
5868

5969
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
6070
const label = i18nBundle.getText(i18nLabel);
@@ -65,7 +75,7 @@ const MessageViewButton = forwardRef<ButtonDomRef, MessageViewButtonProptypes>((
6575
icon={icon}
6676
{...rest}
6777
data-type={type}
68-
tooltip={tooltip ?? label}
78+
tooltip={tooltip ?? i18nBundle.getText(title)}
6979
accessibleName={accessibleName ?? label}
7080
>
7181
{counter > 1 && counter}

0 commit comments

Comments
 (0)