Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve and propagate dir to overlay and items (#879) #880

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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