Skip to content

Commit 34257d6

Browse files
fix(alert): long words wrap to next line (#28408)
Issue number: resolves #28406 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> As part of #27898 we updated the radio and checkbox labels to wrap to the next line instead of truncate. However, we did not consider long words. As a result, long words run outside of the container. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - The radio and checkbox labels now break on words too in addition to white space characters. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent d47b7e7 commit 34257d6

8 files changed

+73
-0
lines changed

Diff for: core/src/components/alert/alert.scss

+20
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@
9191
overscroll-behavior-y: contain;
9292
}
9393

94+
.alert-checkbox-label,
95+
.alert-radio-label {
96+
/**
97+
* This allows long words to wrap to the next line
98+
* instead of flowing outside of the container.
99+
*
100+
* The "anywhere" keyword should be used instead
101+
* of the "break-word" keyword since the parent
102+
* container is using flexbox. Flex relies on min-content and
103+
* max-content intrinsic sizes to structure the layout. Flex will
104+
* wrap content only until it reaches its min-content intrinsic size
105+
* which in this case is equal to the longest word in this container.
106+
* "break-word" does not shrink the min-content intrinsic size
107+
* of the flex item which causes the long word to still overflow.
108+
* "anywhere" on the other hand does shrink the min-content
109+
* intrinsic size which allows the long word to wrap to the next line.
110+
*/
111+
overflow-wrap: anywhere;
112+
}
113+
94114
/**
95115
* Scrollbars on mobile devices will be hidden.
96116
* Users can still scroll the content by swiping.

Diff for: core/src/components/alert/test/a11y/alert.e2e.ts

+53
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,59 @@ const testAria = async (
2828
expect(ariaDescribedBy).toBe(expectedAriaDescribedBy);
2929
};
3030

31+
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
32+
test.describe(title('alert: text wrapping'), () => {
33+
test('should break on words and white spaces for radios', async ({ page }) => {
34+
await page.setContent(
35+
`
36+
<ion-alert header='Text Wrapping'></ion-alert>
37+
38+
<script>
39+
const alert = document.querySelector('ion-alert');
40+
alert.inputs = [
41+
{ type: 'radio', value: 'a', label: 'ThisIsAllOneReallyLongWordThatShouldWrap' },
42+
{ type: 'radio', value: 'b', label: 'These are separate words that should wrap' }
43+
];
44+
</script>
45+
`,
46+
config
47+
);
48+
49+
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
50+
const alert = page.locator('ion-alert');
51+
52+
await alert.evaluate((el: HTMLIonAlertElement) => el.present());
53+
await ionAlertDidPresent.next();
54+
55+
await expect(page).toHaveScreenshot(screenshot(`alert-radio-text-wrap`));
56+
});
57+
test('should break on words and white spaces for checkboxes', async ({ page }) => {
58+
await page.setContent(
59+
`
60+
<ion-alert header='Text Wrapping'></ion-alert>
61+
62+
<script>
63+
const alert = document.querySelector('ion-alert');
64+
alert.inputs = [
65+
{ type: 'checkbox', value: 'a', label: 'ThisIsAllOneReallyLongWordThatShouldWrap' },
66+
{ type: 'checkbox', value: 'b', label: 'These are separate words that should wrap' }
67+
];
68+
</script>
69+
`,
70+
config
71+
);
72+
73+
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
74+
const alert = page.locator('ion-alert');
75+
76+
await alert.evaluate((el: HTMLIonAlertElement) => el.present());
77+
await ionAlertDidPresent.next();
78+
79+
await expect(page).toHaveScreenshot(screenshot(`alert-checkbox-text-wrap`));
80+
});
81+
});
82+
});
83+
3184
configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
3285
test.describe(title('alert: a11y'), () => {
3386
test.beforeEach(async ({ page }) => {

0 commit comments

Comments
 (0)