Skip to content

Commit

Permalink
fix(group): prevent horizontal overflow in IE11 instead of wrapping
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
platosha authored and web-padawan committed Jun 11, 2019
1 parent ab9ad53 commit 6c97ade
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/vaadin-checkbox-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<style>
:host {
display: inline-flex;

/* Prevent horizontal overflow in IE 11 instead of wrapping checkboxes */
max-width: 100%;
}

:host::before {
Expand All @@ -29,6 +32,9 @@
.vaadin-group-field-container {
display: flex;
flex-direction: column;

/* Prevent horizontal overflow in IE 11 instead of wrapping checkboxes */
width: 100%;
}

[part="label"]:empty {
Expand Down
3 changes: 2 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"sinon": false,
"expect": false,
"gemini": false,
"MockInteractions": false
"MockInteractions": false,
"animationFrameFlush": false
}
}
55 changes: 55 additions & 0 deletions test/vaadin-checkbox-group_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@
</dom-bind>
</test-fixture>

<test-fixture id="wrapping">
<template>
<vaadin-checkbox-group>
<vaadin-checkbox value="c_1">Checkbox 1</vaadin-checkbox>
<vaadin-checkbox value="c_2">Checkbox 2</vaadin-checkbox>
<vaadin-checkbox value="c_3">Checkbox 3</vaadin-checkbox>
<vaadin-checkbox value="c_4">Checkbox 4</vaadin-checkbox>
<vaadin-checkbox value="c_5">Checkbox 5</vaadin-checkbox>
<vaadin-checkbox value="c_6">Checkbox 6</vaadin-checkbox>
<vaadin-checkbox value="c_7">Checkbox 7</vaadin-checkbox>
<vaadin-checkbox value="c_8">Checkbox 8</vaadin-checkbox>
<vaadin-checkbox value="c_9">Checkbox 9</vaadin-checkbox>
<vaadin-checkbox value="c_10">Checkbox 10</vaadin-checkbox>
<vaadin-checkbox value="c_11">Checkbox 11</vaadin-checkbox>
<vaadin-checkbox value="c_12">Checkbox 12</vaadin-checkbox>
</vaadin-checkbox-group>
</template>
</test-fixture>

<script>
describe('vaadin-checkbox-group', () => {

Expand Down Expand Up @@ -422,5 +441,41 @@
expect(vaadinCheckboxList[2].checked).to.be.true;
});
});

describe('vaadin-checkbox-group wrapping', () => {
let vaadinCheckboxGroup;

beforeEach((done) => {
vaadinCheckboxGroup = fixture('wrapping');
vaadinCheckboxGroup._observer.flush();
animationFrameFlush(done);
});

it('should not overflow horizontally', () => {
const parentWidth = vaadinCheckboxGroup.parentElement.offsetWidth;

expect(vaadinCheckboxGroup.offsetWidth).to.be.lte(parentWidth);
expect(
vaadinCheckboxGroup
.shadowRoot
.querySelector('[part~="group-field"]')
.offsetWidth
).to.be.lte(parentWidth);
});

it('should wrap checkboxes', () => {
const checkboxes = Array.from(vaadinCheckboxGroup.children);
const {top: firstTop, left: firstLeft} =
checkboxes[0].getBoundingClientRect();

const wrappedCheckboxes = Array.from(checkboxes)
.slice(1)
.filter(checkbox => checkbox.getBoundingClientRect().top > firstTop);

expect(wrappedCheckboxes).not.be.empty;
expect(wrappedCheckboxes[0].getBoundingClientRect().left)
.to.equal(firstLeft);
});
});
</script>
</body>

0 comments on commit 6c97ade

Please sign in to comment.