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

RTL fix for range list #6417

Merged
merged 6 commits into from Jul 20, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/ha-date-range-picker.ts
Expand Up @@ -17,6 +17,7 @@ import "./ha-svg-icon";
import "@polymer/paper-input/paper-input";
import "@material/mwc-list/mwc-list";
import "./date-range-picker";
import { computeRTLDirection } from "../common/util/compute_rtl";

export interface DateRangePickerRanges {
[key: string]: [Date, Date];
Expand All @@ -36,12 +37,20 @@ export class HaDateRangePicker extends LitElement {

@property({ type: Boolean }) private _hour24format = false;

@property({ type: String }) private _rtlDirection = "ltr";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not call this _rtlDirection as its value isn't a boolean, let's call it _textDirection or _direction or _dir


protected updated(changedProps: PropertyValues) {
if (changedProps.has("hass")) {
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (!oldHass || oldHass.language !== this.hass.language) {
this._hour24format = this._compute24hourFormat();
}
if (
!oldHass ||
computeRTLDirection(oldHass) !== computeRTLDirection(this.hass)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just compare the languages, you are now doing 2 computeRTLDirection extra.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But lang can change and RTLDirection may not change. It is inefficient however I though re-rendering was the thing to avoid at almost all cost??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Joint both checks

) {
this._rtlDirection = computeRTLDirection(this.hass);
}
}
}

Expand Down Expand Up @@ -76,7 +85,11 @@ export class HaDateRangePicker extends LitElement {
></paper-input>
</div>
${this.ranges
? html`<div slot="ranges" class="date-range-ranges">
? html`<div
slot="ranges"
class="date-range-ranges"
.dir=${this._rtlDirection}
>
<mwc-list @click=${this._setDateRange}>
${Object.entries(this.ranges).map(
([name, dates]) => html`<mwc-list-item
Expand Down Expand Up @@ -161,6 +174,9 @@ export class HaDateRangePicker extends LitElement {
.date-range-ranges {
border-right: 1px solid var(--divider-color);
}
.date-range-ranges.rtl {
direction: rtl;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I did. Oops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


@media only screen and (max-width: 800px) {
.date-range-ranges {
Expand Down