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

Add rtl support and tests #97

Merged
merged 6 commits into from
Apr 9, 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
16 changes: 8 additions & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
],
"dependencies": {
"polymer": "^2.0.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.4.0",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.0.0",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.1.0",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.1.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.5.2",
"vaadin-element-mixin": "vaadin/vaadin-element-mixin#^2.3.2",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.6.0",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.3.0",
"vaadin-license-checker": "vaadin/license-checker#^2.1.0",
"vaadin-dialog": "vaadin/vaadin-dialog#^2.1.0",
"vaadin-button": "vaadin/vaadin-button#^2.1.0",
"vaadin-overlay": "vaadin/vaadin-overlay#^3.2.0"
"vaadin-dialog": "vaadin/vaadin-dialog#^2.3.0",
"vaadin-button": "vaadin/vaadin-button#^2.3.0-alpha1",
"vaadin-overlay": "vaadin/vaadin-overlay#^3.4.0"
},
"devDependencies": {
"iron-component-page": "^3.0.0",
"iron-demo-helpers": "^2.0.0",
"webcomponentsjs": "^1.0.0",
"web-component-tester": "^6.1.5",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.0.0",
"vaadin-demo-helpers": "vaadin/vaadin-demo-helpers#^3.1.0-alpha1",
"vaadin-icons": "vaadin/vaadin-icons#^4.2.0",
"iron-test-helpers": "^2.0.0"
}
Expand Down
23 changes: 23 additions & 0 deletions src/vaadin-confirm-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,27 @@ <h3 class="header">[[header]]</h3>
}
}

attributeChangedCallback(name, oldValue, newValue) {
super.attributeChangedCallback(name, oldValue, newValue);
if (name === 'dir') {
const value = newValue === 'rtl';
this.__isRTL = value;
this.opened && this.__toggleContentRTL(value);
}
}

__toggleContentRTL(rtl) {
const contentBlock = this.$.dialog.$.overlay.content.querySelector('#content');
const footerBlock = this.$.dialog.$.overlay.content.querySelector('[part=footer]');
if (rtl) {
contentBlock.setAttribute('dir', 'rtl');
footerBlock.setAttribute('dir', 'rtl');
} else {
contentBlock.removeAttribute('dir');
footerBlock.removeAttribute('dir');
}
}

_openedChanged() {
if (!this.opened) {
return;
Expand All @@ -254,6 +275,8 @@ <h3 class="header">[[header]]</h3>
}
});

this.opened && this.__toggleContentRTL(this.__isRTL);

Polymer.RenderStatus.beforeNextRender(this, () => {
var confirmButton = this._confirmButton || this.$.dialog.$.overlay.content.querySelector('#confirm');
confirmButton.focus();
Expand Down
16 changes: 16 additions & 0 deletions test/alert-api-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@
var confirmButtonText = confirmButton.textContent;
expect(confirmButtonText).to.contain('Of course');
});

describe('RTL', function() {
it('should apply rtl to content and footer before openning', function() {
confirm.setAttribute('dir', 'rtl');
confirm.opened = true;
expect(content.querySelector('#content').getAttribute('dir')).to.be.equal('rtl');
expect(content.querySelector('[part="footer"]').getAttribute('dir')).to.be.equal('rtl');
});

it('should apply rtl to content and footer when opened', function() {
confirm.opened = true;
confirm.setAttribute('dir', 'rtl');
expect(content.querySelector('#content').getAttribute('dir')).to.be.equal('rtl');
expect(content.querySelector('[part="footer"]').getAttribute('dir')).to.be.equal('rtl');
});
});
});
</script>
</body>
3 changes: 3 additions & 0 deletions test/visual/custom-buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<link rel="import" href="../../../vaadin-icons/vaadin-icons.html">
`);

const direction = window.location.search.replace(/.*dir=(\w+).*/, '$1') || 'ltr';
document.documentElement.setAttribute('dir', direction);

window.addEventListener('WebComponentsReady', function() {
setTimeout(function() {
window.ShadyDOM && window.ShadyDOM.flush(); // Force DOM composition
Expand Down
3 changes: 3 additions & 0 deletions test/visual/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<link rel="import" href="../../theme/${theme}/vaadin-confirm-dialog.html">
`);

const direction = window.location.search.replace(/.*dir=(\w+).*/, '$1') || 'ltr';
document.documentElement.setAttribute('dir', direction);

window.addEventListener('WebComponentsReady', function() {
setTimeout(function() {
window.ShadyDOM && window.ShadyDOM.flush(); // Force DOM composition
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 20 additions & 18 deletions test/visual/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@ gemini.suite('vaadin-confirm-dialog', function(rootSuite) {
.before(wait)
.after(goToAboutBlank);

['lumo', 'material'].forEach(theme => {
['ltr', 'rtl'].forEach(direction => {
['lumo', 'material'].forEach(theme => {

gemini.suite(`default-tests-${theme}`, function(suite) {
suite
.setUrl(`default.html?theme=${theme}`)
.setCaptureElements('body')
.capture('confirm-dialog');
});
gemini.suite(`default-tests-${theme}-${direction}`, function(suite) {
suite
.setUrl(`default.html?theme=${theme}&dir=${direction}`)
.setCaptureElements('body')
.capture('confirm-dialog');
});

gemini.suite(`three-actions-tests-${theme}`, function(suite) {
suite
.setUrl(`three-actions.html?theme=${theme}`)
.setCaptureElements('body')
.capture('confirm-dialog');
});
gemini.suite(`three-actions-tests-${theme}-${direction}`, function(suite) {
suite
.setUrl(`three-actions.html?theme=${theme}&dir=${direction}`)
.setCaptureElements('body')
.capture('confirm-dialog');
});

gemini.suite(`custom-buttons-tests-${theme}`, function(suite) {
suite
.setUrl(`custom-buttons.html?theme=${theme}`)
.setCaptureElements('body')
.capture('confirm-dialog');
gemini.suite(`custom-buttons-tests-${theme}-${direction}`, function(suite) {
suite
.setUrl(`custom-buttons.html?theme=${theme}&dir=${direction}`)
.setCaptureElements('body')
.capture('confirm-dialog');
});
});
});

Expand Down
3 changes: 3 additions & 0 deletions test/visual/three-actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<link rel="import" href="../../theme/${theme}/vaadin-confirm-dialog.html">
`);

const direction = window.location.search.replace(/.*dir=(\w+).*/, '$1') || 'ltr';
document.documentElement.setAttribute('dir', direction);

window.addEventListener('WebComponentsReady', function() {
setTimeout(function() {
window.ShadyDOM && window.ShadyDOM.flush(); // Force DOM composition
Expand Down
24 changes: 21 additions & 3 deletions theme/lumo/vaadin-confirm-dialog-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@

.cancel-button {
flex-grow: 1;
}

:not([dir="rtl"]) > .cancel-button {
margin-left: calc(var(--lumo-space-s) * -1);
}

.confirm-button {
:not([dir="rtl"]) > .confirm-button {
margin-right: calc(var(--lumo-space-s) * -1);
}

.reject-button,
.confirm-button {
:not([dir="rtl"]) > .reject-button,
:not([dir="rtl"]) > .confirm-button {
margin-left: var(--lumo-space-s);
}

Expand Down Expand Up @@ -92,6 +95,21 @@
margin-bottom: var(--lumo-space-s);
}
}

/* RTL specific styles */

[dir="rtl"] > .cancel-button {
margin-right: calc(var(--lumo-space-s) * -1);
}

[dir="rtl"] > .confirm-button {
margin-left: calc(var(--lumo-space-s) * -1);
}

[dir="rtl"] > .reject-button,
[dir="rtl"] > .confirm-button {
margin-right: var(--lumo-space-s);
}
</style>
</template>
</dom-module>
28 changes: 26 additions & 2 deletions theme/material/vaadin-confirm-dialog-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
margin-right: -16px;
}

[part="footer"] div:nth-child(-n + 2) vaadin-button,
[part="footer"] div:nth-child(-n + 2) ::slotted(*) {
[part="footer"]:not([dir="rtl"]) div:nth-child(-n + 2) vaadin-button,
[part="footer"]:not([dir="rtl"]) div:nth-child(-n + 2) ::slotted(*) {
margin-right: 8px;
}

Expand All @@ -41,6 +41,30 @@
[part="footer"] div:nth-last-child(1) ::slotted(*) {
margin-top: 8px;
}

/* RTL specific styles */

[part="footer"][dir="rtl"] div:nth-child(-n + 2) vaadin-button,
[part="footer"][dir="rtl"] div:nth-child(-n + 2) ::slotted(*) {
margin-left: 0;
}
}

/* RTL specific styles */

[dir="rtl"] > [part="message"] {
margin-left: 24px;
margin-right: 0;
}

[part="footer"][dir="rtl"] {
margin-left: -16px;
margin-right: 0;
}

[part="footer"][dir="rtl"] div:nth-child(-n + 2) vaadin-button,
[part="footer"][dir="rtl"] div:nth-child(-n + 2) ::slotted(*) {
margin-left: 8px;
}
</style>
</template>
Expand Down