fix: hide text align for labelled arrows (#6339)

* fix: hide text align for labelled arrows

* lintttt

* since we fetch seledcted Elements including the bound text hence this block can be removed

* fix
This commit is contained in:
Aakansha Doshi 2023-03-14 17:21:46 +05:30 committed by GitHub
parent ab49cad6b1
commit f6e8be399e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 6 deletions

View File

@ -745,16 +745,19 @@ export const actionChangeTextAlign = register({
value: "left", value: "left",
text: t("labels.left"), text: t("labels.left"),
icon: TextAlignLeftIcon, icon: TextAlignLeftIcon,
testId: "align-left",
}, },
{ {
value: "center", value: "center",
text: t("labels.center"), text: t("labels.center"),
icon: TextAlignCenterIcon, icon: TextAlignCenterIcon,
testId: "align-horizontal-center",
}, },
{ {
value: "right", value: "right",
text: t("labels.right"), text: t("labels.right"),
icon: TextAlignRightIcon, icon: TextAlignRightIcon,
testId: "align-right",
}, },
]} ]}
value={getFormValue( value={getFormValue(

View File

@ -30,7 +30,10 @@ import clsx from "clsx";
import { actionToggleZenMode } from "../actions"; import { actionToggleZenMode } from "../actions";
import "./Actions.scss"; import "./Actions.scss";
import { Tooltip } from "./Tooltip"; import { Tooltip } from "./Tooltip";
import { shouldAllowVerticalAlign } from "../element/textElement"; import {
shouldAllowVerticalAlign,
suppportsHorizontalAlign,
} from "../element/textElement";
export const SelectedShapeActions = ({ export const SelectedShapeActions = ({
appState, appState,
@ -122,7 +125,8 @@ export const SelectedShapeActions = ({
{renderAction("changeFontFamily")} {renderAction("changeFontFamily")}
{renderAction("changeTextAlign")} {suppportsHorizontalAlign(targetElements) &&
renderAction("changeTextAlign")}
</> </>
)} )}

View File

@ -668,14 +668,24 @@ export const shouldAllowVerticalAlign = (
} }
return true; return true;
} }
const boundTextElement = getBoundTextElement(element); return false;
if (boundTextElement) { });
if (isArrowElement(element)) { };
export const suppportsHorizontalAlign = (
selectedElements: NonDeletedExcalidrawElement[],
) => {
return selectedElements.some((element) => {
const hasBoundContainer = isBoundToContainer(element);
if (hasBoundContainer) {
const container = getContainerElement(element);
if (isTextElement(element) && isArrowElement(container)) {
return false; return false;
} }
return true; return true;
} }
return false;
return isTextElement(element);
}); });
}; };

View File

@ -1179,5 +1179,17 @@ describe("Test Linear Elements", () => {
easy" easy"
`); `);
}); });
it("should not render horizontal align tool when element selected", () => {
createTwoPointerLinearElement("arrow");
const arrow = h.elements[0] as ExcalidrawLinearElement;
createBoundTextElement(DEFAULT_TEXT, arrow);
API.setSelectedElements([arrow]);
expect(queryByTestId(container, "align-left")).toBeNull();
expect(queryByTestId(container, "align-horizontal-center")).toBeNull();
expect(queryByTestId(container, "align-right")).toBeNull();
});
}); });
}); });