Skip to content

Commit

Permalink
Preserve and propagate dir to overlay and items (#879) (#880)
Browse files Browse the repository at this point in the history
* Preserve and propagate dir to overlay and items

* Enhance the test with documentElement dir
  • Loading branch information
yuriy-fix committed May 26, 2020
1 parent b1e7734 commit abf49f0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/vaadin-combo-box-dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
return 'vaadin-combo-box-overlay';
}

connectedCallback() {
super.connectedCallback();

const dropdown = this.__dataHost;
const comboBoxOverlay = dropdown.getRootNode().host;
const comboBox = comboBoxOverlay && comboBoxOverlay.getRootNode().host;
const hostDir = comboBox && comboBox.getAttribute('dir');
if (hostDir) {
this.setAttribute('dir', hostDir);
}
}

ready() {
super.ready();
const loader = document.createElement('div');
Expand Down
5 changes: 5 additions & 0 deletions src/vaadin-combo-box-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
this.$.content.appendChild(this._itemTemplateInstance.root);
}
}

const hostDir = this._comboBox.getAttribute('dir');
if (hostDir) {
this.setAttribute('dir', hostDir);
}
}

_render() {
Expand Down
7 changes: 7 additions & 0 deletions test/item-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
const content = firstItem.shadowRoot.querySelector('[part="content"]');
expect(getComputedStyle(content).getPropertyValue('display')).to.equal('block');
});

it('should preserve and propagate dir to the items', () => {
combobox.close();
combobox.setAttribute('dir', 'ltr');
combobox.open();
expect(firstItem.getAttribute('dir')).to.eql('ltr');
});
});
</script>

Expand Down
11 changes: 11 additions & 0 deletions test/vaadin-combo-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@
});
});

describe('Direction', () => {
it('should preserve and propagate dir to the dropdown overlay', () => {
comboBox.setAttribute('dir', 'ltr');
document.documentElement.setAttribute('dir', 'rtl');
comboBox.items = ['foo', 'bar'];
comboBox.open();
expect(comboBox.$.overlay.$.dropdown.$.overlay.getAttribute('dir')).to.eql('ltr');
document.documentElement.removeAttribute('dir');
});
});

describe('items property', () => {
it('should have undefined by default', () => {
expect(comboBox.items).to.be.undefined;
Expand Down

0 comments on commit abf49f0

Please sign in to comment.