Skip to content
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
33 changes: 33 additions & 0 deletions src/visualBuilder/utils/__test__/enableInlineEditing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,39 @@ describe("enableInlineEditing", () => {
expect(editableElement.focus).toHaveBeenCalled();
});

it("should set dir=auto so the caret follows the text direction", () => {
Comment thread
karancs06 marked this conversation as resolved.
enableInlineEditing({
expectedFieldData: "Test content",
editableElement,
fieldType: FieldDataType.SINGLELINE,
elements: {
visualBuilderContainer,
resizeObserver,
lastEditedField: null,
},
});

expect(editableElement.getAttribute("dir")).toBe("auto");
});

it("should set dir=auto on the pseudo element when one is created", () => {
// Content differs from expected, so a pseudo editable element is used.
enableInlineEditing({
expectedFieldData: "Different content",
editableElement,
fieldType: FieldDataType.SINGLELINE,
elements: {
visualBuilderContainer,
resizeObserver,
lastEditedField: null,
},
});

const pseudoElement =
generatePseudoEditableElement.mock.results[0].value;
expect(pseudoElement.getAttribute("dir")).toBe("auto");
});

it("should handle multiline fields correctly", () => {
enableInlineEditing({
expectedFieldData: "Test content",
Expand Down
10 changes: 10 additions & 0 deletions src/visualBuilder/utils/__test__/getStyleOfAnElement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ describe("getStyleOfAnElement", () => {
width: "100px",
});
});

test("it should not copy direction/unicode-bidi so dir=auto can govern", () => {
const elem = document.createElement("div");
elem.style.direction = "rtl";
elem.style.unicodeBidi = "isolate";

const style = getStyleOfAnElement(elem);
expect(style).not.toHaveProperty("direction");
expect(style).not.toHaveProperty("unicode-bidi");
});
});
2 changes: 2 additions & 0 deletions src/visualBuilder/utils/enableInlineEditing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export function enableInlineEditing({
}

actualEditableField.setAttribute("contenteditable", "true");
// caret follows the text direction (fixes LTR caret on RTL content)
actualEditableField.setAttribute("dir", "auto");
Comment thread
karancs06 marked this conversation as resolved.
actualEditableField.addEventListener("input", handleFieldInput);
actualEditableField.addEventListener("keydown", handleFieldKeyDown);

Expand Down
3 changes: 3 additions & 0 deletions src/visualBuilder/utils/getStyleOfAnElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default function getStyleOfAnElement(element: HTMLElement): {
"margin-bottom",
"-webkit-user-modify",
"cursor",
// let the pseudo element's dir="auto" decide direction, not inline copies
"direction",
"unicode-bidi",
];

const styles: { [key: string]: string } = {};
Expand Down
1 change: 1 addition & 0 deletions src/visualBuilder/utils/handleIndividualFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function cleanIndividualFieldResidual(elements: {
VISUAL_BUILDER_FIELD_TYPE_ATTRIBUTE_KEY
);
previousSelectedEditableDOM.removeAttribute("contenteditable");
previousSelectedEditableDOM.removeAttribute("dir");
previousSelectedEditableDOM.removeEventListener(
"input",
handleFieldInput
Expand Down
Loading