Skip to content

Commit

Permalink
fix(alert): prevent content from overflowing alert
Browse files Browse the repository at this point in the history
- flexbox has some quirks with overflow
- setting min-width: 0 prevents the content from overflowing

fixes vmware-clarity#137
  • Loading branch information
Ashley Ryan committed Aug 4, 2022
1 parent d8f4565 commit 97d29e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions projects/core/src/alert/alert.element.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cds-internal-close-button {
display: flex;
min-height: #{$cds-global-space-6};
padding: var(--container-padding);
min-width: 0;
}

.alert-icon-wrapper {
Expand All @@ -70,6 +71,10 @@ cds-internal-close-button {
line-height: $lightweight-alert-line-height;
}

.alert-content {
min-width: 0;
}

::slotted(cds-alert-actions) {
--action-text-color: var(--color);
--action-size: #{$lightweight-alert-line-height};
Expand Down
16 changes: 16 additions & 0 deletions projects/core/src/alert/alert.element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ describe('Alert element – ', () => {
await componentIsStable(component);
expect(component.querySelectorAll('cds-internal-close-button').length).toBe(0);
});

it('should not let content overflow alert', async () => {
const testElement2 = await createTestElement(html` <cds-alert-group status="info" style="width: 200px">
<cds-alert>
<pre style="overflow-x: auto">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</pre
>
</cds-alert>
</cds-alert-group>`);
component = testElement2.querySelector<CdsAlert>('cds-alert');
const content = component.querySelector('pre');

expect(content.getBoundingClientRect().width).toBeLessThan(component.getBoundingClientRect().width);

removeTestElement(testElement);
});
});

describe('custom icons: ', () => {
Expand Down

0 comments on commit 97d29e3

Please sign in to comment.