mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
RTL Auth fix (#12746)
This commit is contained in:
parent
e54802bd87
commit
10f63180eb
@ -1,3 +1,4 @@
|
|||||||
|
import { LitElement } from "lit";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
export function computeRTL(hass: HomeAssistant) {
|
export function computeRTL(hass: HomeAssistant) {
|
||||||
@ -15,3 +16,21 @@ export function computeRTLDirection(hass: HomeAssistant) {
|
|||||||
export function emitRTLDirection(rtl: boolean) {
|
export function emitRTLDirection(rtl: boolean) {
|
||||||
return rtl ? "rtl" : "ltr";
|
return rtl ? "rtl" : "ltr";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function computeDirectionStyles(isRTL: boolean, element: LitElement) {
|
||||||
|
const direction: string = emitRTLDirection(isRTL);
|
||||||
|
setDirectionStyles(direction, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setDirectionStyles(direction: string, element: LitElement) {
|
||||||
|
element.style.direction = direction;
|
||||||
|
element.style.setProperty("--direction", direction);
|
||||||
|
element.style.setProperty(
|
||||||
|
"--float-start",
|
||||||
|
direction === "ltr" ? "left" : "right"
|
||||||
|
);
|
||||||
|
element.style.setProperty(
|
||||||
|
"--float-end",
|
||||||
|
direction === "ltr" ? "right" : "left"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -103,6 +103,9 @@ export class HaTextSelector extends LitElement {
|
|||||||
--mdc-icon-button-size: 24px;
|
--mdc-icon-button-size: 24px;
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
|
inset-inline-start: initial;
|
||||||
|
inset-inline-end: 16px;
|
||||||
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ export class HaTextField extends TextFieldBase {
|
|||||||
inset-inline-end: initial !important;
|
inset-inline-end: initial !important;
|
||||||
transform-origin: var(--float-start);
|
transform-origin: var(--float-start);
|
||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
|
transform-origin: var(--float-start);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mdc-text-field--with-leading-icon.mdc-text-field--filled
|
.mdc-text-field--with-leading-icon.mdc-text-field--filled
|
||||||
|
@ -3,6 +3,8 @@ import { property } from "lit/decorators";
|
|||||||
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
||||||
import { Constructor, Resources } from "../types";
|
import { Constructor, Resources } from "../types";
|
||||||
import { getLocalLanguage, getTranslation } from "../util/common-translation";
|
import { getLocalLanguage, getTranslation } from "../util/common-translation";
|
||||||
|
import { translationMetadata } from "../resources/translations-metadata";
|
||||||
|
import { computeDirectionStyles } from "../common/util/compute_rtl";
|
||||||
|
|
||||||
const empty = () => "";
|
const empty = () => "";
|
||||||
|
|
||||||
@ -25,6 +27,14 @@ export const litLocalizeLiteMixin = <T extends Constructor<LitElement>>(
|
|||||||
this._initializeLocalizeLite();
|
this._initializeLocalizeLite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
|
super.firstUpdated(changedProps);
|
||||||
|
computeDirectionStyles(
|
||||||
|
translationMetadata.translations[this.language!].isRTL,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
if (changedProperties.get("translationFragment")) {
|
if (changedProperties.get("translationFragment")) {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { atLeastVersion } from "../common/config/version";
|
import { atLeastVersion } from "../common/config/version";
|
||||||
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
import { computeLocalize, LocalizeFunc } from "../common/translations/localize";
|
||||||
import { computeRTLDirection } from "../common/util/compute_rtl";
|
import {
|
||||||
|
computeRTLDirection,
|
||||||
|
setDirectionStyles,
|
||||||
|
} from "../common/util/compute_rtl";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
import {
|
import {
|
||||||
getHassTranslations,
|
getHassTranslations,
|
||||||
@ -188,17 +191,8 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
|
|
||||||
private _applyDirection(hass: HomeAssistant) {
|
private _applyDirection(hass: HomeAssistant) {
|
||||||
const direction = computeRTLDirection(hass);
|
const direction = computeRTLDirection(hass);
|
||||||
this.style.direction = direction;
|
|
||||||
document.dir = direction;
|
document.dir = direction;
|
||||||
this.style.setProperty("--direction", direction);
|
setDirectionStyles(direction, this);
|
||||||
this.style.setProperty(
|
|
||||||
"--float-start",
|
|
||||||
direction === "ltr" ? "left" : "right"
|
|
||||||
);
|
|
||||||
this.style.setProperty(
|
|
||||||
"--float-end",
|
|
||||||
direction === "ltr" ? "right" : "left"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user