Skip to content

Commit 5127134

Browse files
authored
fix(MessageViewButton): add default tooltip & aria-label (#6597)
Fixes #6594
1 parent 688ef7b commit 5127134

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

.storybook/mockData/generateMessageItems.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ const informationMessageItems = (count) => {
2424
));
2525
};
2626

27-
const successMessageItems = (count) => {
28-
if (!count) {
29-
return [];
30-
}
31-
return new Array(count).fill('').map((_, index) => (
32-
<MessageItem
33-
key={`SuccessMessage${index}`}
34-
titleText={'Success Message'}
35-
type={ValueState.Success}
36-
groupName={`Group${index}`}
37-
>
38-
{LoremIpsum}
39-
</MessageItem>
40-
));
41-
};
42-
4327
const warningMessageItems = (count) => {
4428
if (!count) {
4529
return [];
@@ -75,6 +59,5 @@ const errorMessageItems = (count) => {
7559
export const generateMessageItems = (numberOfMessageTypes) => [
7660
...informationMessageItems(numberOfMessageTypes.information),
7761
...warningMessageItems(numberOfMessageTypes.warning),
78-
...successMessageItems(numberOfMessageTypes.success),
7962
...errorMessageItems(numberOfMessageTypes.error)
8063
];

packages/main/src/components/MessageView/MessageView.stories.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {
1313
import { Bar } from '../../webComponents/Bar/index.js';
1414
import { Button } from '../../webComponents/Button/index.js';
1515
import { Dialog as OriginalDialog } from '../../webComponents/Dialog';
16-
import { Link } from '../../webComponents/Link/index.js';
1716
import { ResponsivePopover as OriginalResponsivePopover } from '../../webComponents/ResponsivePopover';
1817
import { Title } from '../../webComponents/Title/index.js';
1918
import { FlexBox } from '../FlexBox/index.js';
@@ -60,16 +59,6 @@ const meta = {
6059
>
6160
First Error Message Description.
6261
</MessageItem>,
63-
<MessageItem
64-
key={2}
65-
titleText={'Success Message Type'}
66-
subtitleText={'You can also use subtitles'}
67-
type={ValueState.Success}
68-
counter={2}
69-
>
70-
This is a success message! You can even use{' '}
71-
<Link href={'https://github.com/SAP/ui5-webcomponents-react'}>links here</Link>.
72-
</MessageItem>,
7362
<MessageItem
7463
key={3}
7564
titleText={'Warning Message Type'}

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import alertIcon from '@ui5/webcomponents-icons/dist/alert.js';
44
import errorIcon from '@ui5/webcomponents-icons/dist/error.js';
55
import informationIcon from '@ui5/webcomponents-icons/dist/information.js';
66
import sysEnter2Icon from '@ui5/webcomponents-icons/dist/sys-enter-2.js';
7-
import { useStylesheet } from '@ui5/webcomponents-react-base';
7+
import { useI18nBundle, useStylesheet } from '@ui5/webcomponents-react-base';
88
import { clsx } from 'clsx';
99
import { forwardRef } from 'react';
1010
import { ValueState } from '../../enums/index.js';
11+
import { ERROR_TYPE, WARNING_TYPE, INFORMATION_TYPE, SUCCESS_TYPE } from '../../i18n/i18n-defaults.js';
1112
import type { ButtonDomRef, ButtonPropTypes } from '../../webComponents/index.js';
1213
import { Button } from '../../webComponents/index.js';
1314
import { classNames, styleData } from './MessageViewButton.module.css.js';
@@ -28,30 +29,45 @@ export interface MessageViewButtonProptypes
2829
counter?: number;
2930
}
3031

31-
const getIcon = (type) => {
32+
interface Types {
33+
icon: string;
34+
i18nLabel: { key: string; defaultText: string };
35+
}
36+
37+
const getTypes = (type: MessageViewButtonProptypes['type']): Types => {
3238
switch (type) {
3339
case ValueState.Error:
34-
return errorIcon;
40+
return { icon: errorIcon, i18nLabel: ERROR_TYPE };
3541
case ValueState.Success:
36-
return sysEnter2Icon;
42+
return { icon: sysEnter2Icon, i18nLabel: WARNING_TYPE };
3743
case ValueState.Warning:
38-
return alertIcon;
44+
return { icon: alertIcon, i18nLabel: INFORMATION_TYPE };
3945
default:
40-
return informationIcon;
46+
return { icon: informationIcon, i18nLabel: SUCCESS_TYPE };
4147
}
4248
};
4349

4450
/**
4551
* The `MessageViewButton` can be used for opening a `Popover` containing the `MessageView` component. It should always reflect the message `type` with the highest severity.
4652
*/
4753
const MessageViewButton = forwardRef<ButtonDomRef, MessageViewButtonProptypes>((props, ref) => {
48-
const { type = ValueState.Error, counter, className, ...rest } = props;
54+
const { type = ValueState.Error, counter, className, tooltip, accessibleName, ...rest } = props;
4955
useStylesheet(styleData, MessageViewButton.displayName);
5056
const classes = clsx(classNames.btn, className);
51-
const icon = getIcon(type);
57+
const { icon, i18nLabel } = getTypes(type);
5258

59+
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
60+
const label = i18nBundle.getText(i18nLabel);
5361
return (
54-
<Button ref={ref} className={classes} icon={icon} {...rest} data-type={type}>
62+
<Button
63+
ref={ref}
64+
className={classes}
65+
icon={icon}
66+
{...rest}
67+
data-type={type}
68+
tooltip={tooltip ?? label}
69+
accessibleName={accessibleName ?? label}
70+
>
5571
{counter > 1 && counter}
5672
</Button>
5773
);

packages/main/src/i18n/messagebundle.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,15 @@ NO_DATA_FILTERED=No data found. Try adjusting the filter settings.
339339
#XACT: Number of items in a pseudo list
340340
WITH_X_ITEMS=with {0} items
341341

342+
#XACT: Message View error button label
343+
ERROR_TYPE=Error Type
344+
345+
#XACT: Message View warning button label
346+
WARNING_TYPE=Warning Type
347+
348+
#XACT: Message View information button label
349+
INFORMATION_TYPE=Information Type
350+
351+
#XACT: Message View success button label
352+
SUCCESS_TYPE=Success Type
353+

0 commit comments

Comments
 (0)