Skip to content

Commit 3edd16b

Browse files
authored
fix(Toast): fix long words overflowing toast container (#8962)
* fix(Toast): fix long words overflowing toast container * add chromatic stories for Toast
1 parent 835ba2c commit 3edd16b

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import type {Meta, StoryObj} from '@storybook/react';
14+
import React from 'react';
15+
import {SpectrumToast, SpectrumToastValue} from '../src/Toast';
16+
import {UNSTABLE_ToastStateContext} from 'react-aria-components';
17+
import {useToastState} from 'react-stately';
18+
19+
function FakeToast(props: SpectrumToastValue) {
20+
return (
21+
<UNSTABLE_ToastStateContext.Provider value={useToastState()}>
22+
<SpectrumToast
23+
toast={{
24+
key: 'toast',
25+
content: props
26+
}} />
27+
</UNSTABLE_ToastStateContext.Provider>
28+
);
29+
}
30+
31+
const meta: Meta<typeof FakeToast> = {
32+
component: FakeToast,
33+
parameters: {
34+
chromaticProvider: {colorSchemes: ['light'], backgrounds: ['base'], locales: ['en-US'], disableAnimations: true}
35+
},
36+
tags: ['autodocs'],
37+
title: 'S2 Chromatic/Toast'
38+
};
39+
40+
export default meta;
41+
type Story = StoryObj<typeof FakeToast>;
42+
43+
export const Neutral: Story = {
44+
args: {
45+
variant: 'neutral',
46+
children: 'Toast available'
47+
}
48+
};
49+
50+
export const Info: Story = {
51+
args: {
52+
variant: 'info',
53+
children: 'Toasting…'
54+
}
55+
};
56+
57+
export const Positive: Story = {
58+
args: {
59+
variant: 'positive',
60+
children: 'Toast is done!'
61+
}
62+
};
63+
64+
export const Negative: Story = {
65+
args: {
66+
variant: 'negative',
67+
children: 'Toast is burned!'
68+
}
69+
};
70+
71+
export const WithAction: Story = {
72+
args: {
73+
variant: 'positive',
74+
children: 'Toast is done!',
75+
actionLabel: 'Undo'
76+
}
77+
};
78+
79+
export const LongContent: Story = {
80+
args: {
81+
variant: 'info',
82+
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
83+
}
84+
};
85+
86+
export const LongContentWithAction: Story = {
87+
args: {
88+
variant: 'positive',
89+
children: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
90+
actionLabel: 'Undo'
91+
}
92+
};
93+
94+
export const LongWord: Story = {
95+
args: {
96+
variant: 'info',
97+
children: 'LoremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliquaUtenimaminimveniamquisnostrudexercitationullamcolaborisnisiutaliquipeacommodoconsequat.'
98+
}
99+
};

packages/@react-spectrum/s2/src/Toast.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ const toastContent = style({
296296
alignItems: 'baseline',
297297
gridArea: 'content',
298298
cursor: 'default',
299-
width: 'fit'
299+
width: 'fit',
300+
overflowWrap: 'break-word',
301+
wordBreak: 'break-word',
302+
minWidth: 0
300303
});
301304

302305
const controls = style({

packages/@react-spectrum/s2/stories/Toast.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export const Example: Story = {
7979
variant="accent">
8080
Show Long Toast
8181
</Button>
82+
<Button
83+
onPress={() => UNSTABLE_ToastQueue.info('LoremipsumdolorsitametconsecteturadipiscingelitseddoeiusmodtemporincididuntutlaboreetdoloremagnaaliquaUtenimaminimveniamquisnostrudexercitationullamcolaborisnisiutaliquipeacommodoconsequat.', {...args, onClose: action('onClose')})}
84+
variant="accent">
85+
Show Long Word Toast
86+
</Button>
8287
</ButtonGroup>
8388
</>
8489
)

packages/@react-spectrum/s2/style/spectrum-theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ export const style = createTheme({
828828
hyphens: ['none', 'manual', 'auto'] as const,
829829
whiteSpace: ['normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'break-spaces'] as const,
830830
textWrap: ['wrap', 'nowrap', 'balance', 'pretty'] as const,
831-
wordBreak: ['normal', 'break-all', 'keep-all'] as const,
831+
wordBreak: ['normal', 'break-all', 'keep-all', 'break-word'] as const,
832832
overflowWrap: ['normal', 'anywhere', 'break-word'] as const,
833833
boxDecorationBreak: ['slice', 'clone'] as const,
834834

0 commit comments

Comments
 (0)