From 44e2a6d070b219c4ff296506334ee79bc589ed38 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Mon, 29 Apr 2024 19:19:05 +0200 Subject: [PATCH] Tooltip: Use `AccessibleButton` in reusable elements (#12461) * Update reusable elements * Update tests * Make right as default tooltip placement * Add tests --- .../views/elements/AccessibleButton.tsx | 2 +- .../views/elements/CopyableText.tsx | 9 +- src/components/views/elements/ImageView.tsx | 14 +-- src/components/views/elements/SSOButtons.tsx | 5 +- .../views/elements/ToggleSwitch.tsx | 10 ++- .../BeaconListItem-test.tsx.snap | 1 + .../__snapshots__/DialogSidebar-test.tsx.snap | 1 + .../ShareLatestLocation-test.tsx.snap | 1 + .../DevtoolsDialog-test.tsx.snap | 1 + .../views/elements/ImageView-test.tsx | 29 ++++++ .../__snapshots__/ImageView-test.tsx.snap | 88 +++++++++++++++++++ .../AdvancedRoomSettingsTab-test.tsx.snap | 1 + .../tabs/user/LabsUserSettingsTab-test.tsx | 27 +++--- .../PreferencesUserSettingsTab-test.tsx.snap | 1 + 14 files changed, 160 insertions(+), 30 deletions(-) create mode 100644 test/components/views/elements/ImageView-test.tsx create mode 100644 test/components/views/elements/__snapshots__/ImageView-test.tsx.snap diff --git a/src/components/views/elements/AccessibleButton.tsx b/src/components/views/elements/AccessibleButton.tsx index 05b844284a..055818f742 100644 --- a/src/components/views/elements/AccessibleButton.tsx +++ b/src/components/views/elements/AccessibleButton.tsx @@ -138,7 +138,7 @@ const AccessibleButton = forwardRef(function , diff --git a/src/components/views/elements/CopyableText.tsx b/src/components/views/elements/CopyableText.tsx index 7e92b39564..5d9946d2c1 100644 --- a/src/components/views/elements/CopyableText.tsx +++ b/src/components/views/elements/CopyableText.tsx @@ -20,8 +20,7 @@ import classNames from "classnames"; import { _t } from "../../../languageHandler"; import { copyPlaintext } from "../../../utils/strings"; -import { ButtonEvent } from "./AccessibleButton"; -import AccessibleTooltipButton from "./AccessibleTooltipButton"; +import AccessibleButton, { ButtonEvent } from "./AccessibleButton"; interface IProps { children?: React.ReactNode; @@ -53,11 +52,13 @@ const CopyableText: React.FC = ({ children, getTextToCopy, border = true return (
{children} - { + if (!open) onHideTooltip(); + }} />
); diff --git a/src/components/views/elements/ImageView.tsx b/src/components/views/elements/ImageView.tsx index 6f5815e95a..ddc2769c48 100644 --- a/src/components/views/elements/ImageView.tsx +++ b/src/components/views/elements/ImageView.tsx @@ -21,7 +21,6 @@ import FocusLock from "react-focus-lock"; import { MatrixEvent } from "matrix-js-sdk/src/matrix"; import { _t } from "../../../languageHandler"; -import AccessibleTooltipButton from "./AccessibleTooltipButton"; import MemberAvatar from "../avatars/MemberAvatar"; import { ContextMenuTooltipButton } from "../../../accessibility/context_menu/ContextMenuTooltipButton"; import MessageContextMenu from "../context_menus/MessageContextMenu"; @@ -38,6 +37,7 @@ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { presentableTextForFile } from "../../../utils/FileUtils"; +import AccessibleButton from "./AccessibleButton"; // Max scale to keep gaps around the image const MAX_SCALE = 0.95; @@ -513,14 +513,14 @@ export default class ImageView extends React.Component { } const zoomOutButton = ( - ); const zoomInButton = ( - {
{zoomOutButton} {zoomInButton} - - - {contextMenuButton} - = ({ if (mini) { // TODO fallback icon return ( - + {icon} - + ); } diff --git a/src/components/views/elements/ToggleSwitch.tsx b/src/components/views/elements/ToggleSwitch.tsx index 588374d17b..8e595ff234 100644 --- a/src/components/views/elements/ToggleSwitch.tsx +++ b/src/components/views/elements/ToggleSwitch.tsx @@ -18,7 +18,7 @@ limitations under the License. import React from "react"; import classNames from "classnames"; -import AccessibleTooltipButton from "./AccessibleTooltipButton"; +import AccessibleButton from "./AccessibleButton"; interface IProps { // Whether or not this toggle is in the 'on' position. @@ -41,7 +41,7 @@ interface IProps { } // Controlled Toggle Switch element, written with Accessibility in mind -export default ({ checked, disabled = false, onChange, ...props }: IProps): JSX.Element => { +export default ({ checked, disabled = false, onChange, title, tooltip, ...props }: IProps): JSX.Element => { const _onClick = (): void => { if (disabled) return; onChange(!checked); @@ -54,15 +54,17 @@ export default ({ checked, disabled = false, onChange, ...props }: IProps): JSX. }); return ( -
- + ); }; diff --git a/test/components/views/beacon/__snapshots__/BeaconListItem-test.tsx.snap b/test/components/views/beacon/__snapshots__/BeaconListItem-test.tsx.snap index 1d7a958672..f3f1eceb5a 100644 --- a/test/components/views/beacon/__snapshots__/BeaconListItem-test.tsx.snap +++ b/test/components/views/beacon/__snapshots__/BeaconListItem-test.tsx.snap @@ -48,6 +48,7 @@ exports[` when a beacon is live and has locations renders beac
diff --git a/test/components/views/beacon/__snapshots__/DialogSidebar-test.tsx.snap b/test/components/views/beacon/__snapshots__/DialogSidebar-test.tsx.snap index 5ed76727c9..5946edd573 100644 --- a/test/components/views/beacon/__snapshots__/DialogSidebar-test.tsx.snap +++ b/test/components/views/beacon/__snapshots__/DialogSidebar-test.tsx.snap @@ -82,6 +82,7 @@ exports[` renders sidebar correctly with beacons 1`] = `
diff --git a/test/components/views/beacon/__snapshots__/ShareLatestLocation-test.tsx.snap b/test/components/views/beacon/__snapshots__/ShareLatestLocation-test.tsx.snap index 068e4b8ca9..edebf1b0eb 100644 --- a/test/components/views/beacon/__snapshots__/ShareLatestLocation-test.tsx.snap +++ b/test/components/views/beacon/__snapshots__/ShareLatestLocation-test.tsx.snap @@ -19,6 +19,7 @@ exports[` renders share buttons when there is a location
diff --git a/test/components/views/dialogs/__snapshots__/DevtoolsDialog-test.tsx.snap b/test/components/views/dialogs/__snapshots__/DevtoolsDialog-test.tsx.snap index 20b79a2ccb..90198f32e8 100644 --- a/test/components/views/dialogs/__snapshots__/DevtoolsDialog-test.tsx.snap +++ b/test/components/views/dialogs/__snapshots__/DevtoolsDialog-test.tsx.snap @@ -41,6 +41,7 @@ exports[`DevtoolsDialog renders the devtools dialog 1`] = `
diff --git a/test/components/views/elements/ImageView-test.tsx b/test/components/views/elements/ImageView-test.tsx new file mode 100644 index 0000000000..f0475df964 --- /dev/null +++ b/test/components/views/elements/ImageView-test.tsx @@ -0,0 +1,29 @@ +/* + * + * Copyright 2024 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +import React from "react"; +import { render } from "@testing-library/react"; + +import ImageView from "../../../../src/components/views/elements/ImageView"; + +describe("", () => { + it("renders correctly", () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/test/components/views/elements/__snapshots__/ImageView-test.tsx.snap b/test/components/views/elements/__snapshots__/ImageView-test.tsx.snap new file mode 100644 index 0000000000..acd85fb633 --- /dev/null +++ b/test/components/views/elements/__snapshots__/ImageView-test.tsx.snap @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders correctly 1`] = ` +
+
+