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 https://github.com/ionic-team/ionic-framework/pull/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 <hi@ionicframework.com>
This commit is contained in:
Liam DeBeasi
2023-10-25 12:34:36 -04:00
committed by GitHub
parent d47b7e7503
commit 34257d681e
8 changed files with 73 additions and 0 deletions

View File

@ -91,6 +91,26 @@
overscroll-behavior-y: contain;
}
.alert-checkbox-label,
.alert-radio-label {
/**
* This allows long words to wrap to the next line
* instead of flowing outside of the container.
*
* The "anywhere" keyword should be used instead
* of the "break-word" keyword since the parent
* container is using flexbox. Flex relies on min-content and
* max-content intrinsic sizes to structure the layout. Flex will
* wrap content only until it reaches its min-content intrinsic size
* which in this case is equal to the longest word in this container.
* "break-word" does not shrink the min-content intrinsic size
* of the flex item which causes the long word to still overflow.
* "anywhere" on the other hand does shrink the min-content
* intrinsic size which allows the long word to wrap to the next line.
*/
overflow-wrap: anywhere;
}
/**
* Scrollbars on mobile devices will be hidden.
* Users can still scroll the content by swiping.

View File

@ -28,6 +28,59 @@ const testAria = async (
expect(ariaDescribedBy).toBe(expectedAriaDescribedBy);
};
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('alert: text wrapping'), () => {
test('should break on words and white spaces for radios', async ({ page }) => {
await page.setContent(
`
<ion-alert header='Text Wrapping'></ion-alert>
<script>
const alert = document.querySelector('ion-alert');
alert.inputs = [
{ type: 'radio', value: 'a', label: 'ThisIsAllOneReallyLongWordThatShouldWrap' },
{ type: 'radio', value: 'b', label: 'These are separate words that should wrap' }
];
</script>
`,
config
);
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
const alert = page.locator('ion-alert');
await alert.evaluate((el: HTMLIonAlertElement) => el.present());
await ionAlertDidPresent.next();
await expect(page).toHaveScreenshot(screenshot(`alert-radio-text-wrap`));
});
test('should break on words and white spaces for checkboxes', async ({ page }) => {
await page.setContent(
`
<ion-alert header='Text Wrapping'></ion-alert>
<script>
const alert = document.querySelector('ion-alert');
alert.inputs = [
{ type: 'checkbox', value: 'a', label: 'ThisIsAllOneReallyLongWordThatShouldWrap' },
{ type: 'checkbox', value: 'b', label: 'These are separate words that should wrap' }
];
</script>
`,
config
);
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
const alert = page.locator('ion-alert');
await alert.evaluate((el: HTMLIonAlertElement) => el.present());
await ionAlertDidPresent.next();
await expect(page).toHaveScreenshot(screenshot(`alert-checkbox-text-wrap`));
});
});
});
configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
test.describe(title('alert: a11y'), () => {
test.beforeEach(async ({ page }) => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB