Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 18c9b2b

Browse files
authored
Hide indent button in rte (#10149)
* add conditional rendering for indent and unindent buttons * bump rte to 1.1.1
1 parent 49e0228 commit 18c9b2b

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dependencies": {
5858
"@babel/runtime": "^7.12.5",
5959
"@matrix-org/analytics-events": "^0.4.0",
60-
"@matrix-org/matrix-wysiwyg": "^0.23.0",
60+
"@matrix-org/matrix-wysiwyg": "^1.1.1",
6161
"@matrix-org/react-sdk-module-api": "^0.0.3",
6262
"@sentry/browser": "^7.0.0",
6363
"@sentry/tracing": "^7.0.0",

src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ interface FormattingButtonsProps {
8888

8989
export function FormattingButtons({ composer, actionStates }: FormattingButtonsProps): JSX.Element {
9090
const composerContext = useComposerContext();
91+
const isInList = actionStates.unorderedList === "reversed" || actionStates.orderedList === "reversed";
9192
return (
9293
<div className="mx_FormattingButtons">
9394
<Button
@@ -129,18 +130,22 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP
129130
onClick={() => composer.orderedList()}
130131
icon={<NumberedListIcon className="mx_FormattingButtons_Icon" />}
131132
/>
132-
<Button
133-
actionState={actionStates.indent}
134-
label={_td("Indent increase")}
135-
onClick={() => composer.indent()}
136-
icon={<IndentIcon className="mx_FormattingButtons_Icon" />}
137-
/>
138-
<Button
139-
actionState={actionStates.unIndent}
140-
label={_td("Indent decrease")}
141-
onClick={() => composer.unIndent()}
142-
icon={<UnIndentIcon className="mx_FormattingButtons_Icon" />}
143-
/>
133+
{isInList && (
134+
<Button
135+
actionState={actionStates.indent}
136+
label={_td("Indent increase")}
137+
onClick={() => composer.indent()}
138+
icon={<IndentIcon className="mx_FormattingButtons_Icon" />}
139+
/>
140+
)}
141+
{isInList && (
142+
<Button
143+
actionState={actionStates.unindent}
144+
label={_td("Indent decrease")}
145+
onClick={() => composer.unindent()}
146+
icon={<UnIndentIcon className="mx_FormattingButtons_Icon" />}
147+
/>
148+
)}
144149
<Button
145150
actionState={actionStates.quote}
146151
label={_td("Quote")}

test/components/views/rooms/wysiwyg_composer/components/FormattingButtons-test.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import React from "react";
18-
import { render, screen } from "@testing-library/react";
18+
import { cleanup, render, screen } from "@testing-library/react";
1919
import userEvent from "@testing-library/user-event";
2020
import { ActionState, ActionTypes, AllActionStates, FormattingFunctions } from "@matrix-org/matrix-wysiwyg";
2121

@@ -40,7 +40,7 @@ const mockWysiwyg = {
4040
const openLinkModalSpy = jest.spyOn(LinkModal, "openLinkModal");
4141

4242
const testCases: Record<
43-
Exclude<ActionTypes, "undo" | "redo" | "clear">,
43+
Exclude<ActionTypes, "undo" | "redo" | "clear" | "indent" | "unindent">,
4444
{ label: string; mockFormatFn: jest.Func | jest.SpyInstance }
4545
> = {
4646
bold: { label: "Bold", mockFormatFn: mockWysiwyg.bold },
@@ -53,8 +53,6 @@ const testCases: Record<
5353
orderedList: { label: "Numbered list", mockFormatFn: mockWysiwyg.orderedList },
5454
unorderedList: { label: "Bulleted list", mockFormatFn: mockWysiwyg.unorderedList },
5555
quote: { label: "Quote", mockFormatFn: mockWysiwyg.quote },
56-
indent: { label: "Indent increase", mockFormatFn: mockWysiwyg.indent },
57-
unIndent: { label: "Indent decrease", mockFormatFn: mockWysiwyg.unIndent },
5856
};
5957

6058
const createActionStates = (state: ActionState): AllActionStates => {
@@ -162,4 +160,28 @@ describe("FormattingButtons", () => {
162160
expect(screen.getByLabelText(label)).not.toHaveClass("mx_FormattingButtons_Button_hover");
163161
}
164162
});
163+
164+
it("Does not show indent or unindent button when outside a list", () => {
165+
renderComponent();
166+
167+
expect(screen.queryByLabelText("Indent increase")).not.toBeInTheDocument();
168+
expect(screen.queryByLabelText("Indent decrease")).not.toBeInTheDocument();
169+
});
170+
171+
it("Shows indent and unindent buttons when either a single list type is 'reversed'", () => {
172+
const orderedListActive = { ...defaultActionStates, orderedList: "reversed" };
173+
renderComponent({ actionStates: orderedListActive });
174+
175+
expect(screen.getByLabelText("Indent increase")).toBeInTheDocument();
176+
expect(screen.getByLabelText("Indent decrease")).toBeInTheDocument();
177+
178+
cleanup();
179+
180+
const unorderedListActive = { ...defaultActionStates, unorderedList: "reversed" };
181+
182+
renderComponent({ actionStates: unorderedListActive });
183+
184+
expect(screen.getByLabelText("Indent increase")).toBeInTheDocument();
185+
expect(screen.getByLabelText("Indent decrease")).toBeInTheDocument();
186+
});
165187
});

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,10 +1589,10 @@
15891589
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.0-alpha.4.tgz#1b20294e0354c3dcc9c7dc810d883198a4042f04"
15901590
integrity sha512-mdaDKrw3P5ZVCpq0ioW0pV6ihviDEbS8ZH36kpt9stLKHwwDSopPogE6CkQhi0B1jn1yBUtOYi32mBV/zcOR7g==
15911591

1592-
"@matrix-org/matrix-wysiwyg@^0.23.0":
1593-
version "0.23.0"
1594-
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-0.23.0.tgz#32242b18ae9dbb28d920c31f50bbac87ff4317fe"
1595-
integrity sha512-wO5KYznlfsSIMo0R8tyZqfvZrPkQMaL1qBHzhaeKIsC4vK4MnJ9mj6JiS6+XiuHJyc9nqN+IdeUjKyJOnStHaA==
1592+
"@matrix-org/matrix-wysiwyg@^1.1.1":
1593+
version "1.1.1"
1594+
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-wysiwyg/-/matrix-wysiwyg-1.1.1.tgz#a07b13097e72a9bae220a647527d6418c5423827"
1595+
integrity sha512-pp7poyd3vfC/P34ZRj6u2oyLJuex77egeSsIA1MPowBqtrIAmHkji9xviBdXPcDss2zEI4EZuX77JWXtAfaz7Q==
15961596

15971597
"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz":
15981598
version "3.2.14"

0 commit comments

Comments
 (0)