From a66a69744c5ae8da395b5599cbc924c83037eb02 Mon Sep 17 00:00:00 2001 From: Laura Hacker Date: Fri, 15 Jul 2022 10:34:38 -0400 Subject: [PATCH] Refactor InputTooltip to use new Tooltip component (#38822) * Refactor InputTooltip to use new Tooltip component * Formatting --- .eslintrc.js | 5 +++++ .../src/components/InputTooltip.module.scss | 11 ----------- client/web/src/components/InputTooltip.tsx | 19 ++++++------------- .../BatchChangeChangesetsHeader.tsx | 2 ++ .../changesets/ExternalChangesetNode.tsx | 2 ++ .../HiddenExternalChangesetNode.tsx | 2 ++ .../list/HiddenChangesetApplyPreviewNode.tsx | 2 ++ .../preview/list/PreviewListHeader.tsx | 2 ++ .../list/VisibleChangesetApplyPreviewNode.tsx | 4 ++++ .../src/components/Tooltip/Tooltip.tsx | 4 +++- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c1bd91f046c..f04af4cf3eb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -194,6 +194,11 @@ See https://handbook.sourcegraph.com/community/faq#is-all-of-sourcegraph-open-so message: 'When using an icon as a Tooltip trigger, it must have an aria-label attribute and should not be hidden.', }, + { + selector: 'JSXElement[openingElement.name.name="InputTooltip"]', + message: + 'Prefer using the component with an directly, when possible. Please only use when the legacy styling it provides is needed. We will be working to fix style issues with (especially for checkboxes) in the future.', + }, { selector: 'JSXSpreadAttribute[argument.name=/^(props|rest)$/]', message: diff --git a/client/web/src/components/InputTooltip.module.scss b/client/web/src/components/InputTooltip.module.scss index d1cf93904a8..756c6a4563a 100644 --- a/client/web/src/components/InputTooltip.module.scss +++ b/client/web/src/components/InputTooltip.module.scss @@ -2,14 +2,3 @@ display: flex; position: relative; } - -.disabled-tooltip { - cursor: not-allowed; - position: absolute; - height: 100%; - width: 100%; - z-index: 999999; -} -.disabled-btn { - opacity: 0.65; -} diff --git a/client/web/src/components/InputTooltip.tsx b/client/web/src/components/InputTooltip.tsx index c763323d567..51a91571779 100644 --- a/client/web/src/components/InputTooltip.tsx +++ b/client/web/src/components/InputTooltip.tsx @@ -1,6 +1,6 @@ import React from 'react' -import { Button, ButtonProps } from '@sourcegraph/wildcard' +import { Button, ButtonProps, Tooltip, TooltipProps } from '@sourcegraph/wildcard' import styles from './InputTooltip.module.scss' @@ -8,6 +8,7 @@ type ButtonAndInputElementProps = Omit & React.InputHTMLAtt export interface InputTooltipProps extends ButtonAndInputElementProps { tooltip: string + placement?: TooltipProps['placement'] } /** @@ -16,25 +17,17 @@ export interface InputTooltipProps extends ButtonAndInputElementProps { * Disabled elements do not trigger mouse events on hover, and `Tooltip` relies on mouse events. * * All other props are passed to the `input` element. - * - * @deprecated The new `` component from Wildcard now supports disabled inputs automatically, - * please use that component instead. */ export const InputTooltip: React.FunctionComponent> = ({ disabled, tooltip, + placement, type, ...props }) => (
- {disabled ?
: null} -
) diff --git a/client/web/src/enterprise/batches/detail/changesets/BatchChangeChangesetsHeader.tsx b/client/web/src/enterprise/batches/detail/changesets/BatchChangeChangesetsHeader.tsx index 2db589b2f20..f66874d093d 100644 --- a/client/web/src/enterprise/batches/detail/changesets/BatchChangeChangesetsHeader.tsx +++ b/client/web/src/enterprise/batches/detail/changesets/BatchChangeChangesetsHeader.tsx @@ -16,12 +16,14 @@ export const BatchChangeChangesetsHeader: React.FunctionComponent< <> {toggleSelectAll && ( + // eslint-disable-next-line no-restricted-syntax {selectable ? (
+ {/* eslint-disable-next-line no-restricted-syntax*/}
diff --git a/client/web/src/enterprise/batches/detail/changesets/HiddenExternalChangesetNode.tsx b/client/web/src/enterprise/batches/detail/changesets/HiddenExternalChangesetNode.tsx index 6e81c4a9f9e..57624e9b057 100644 --- a/client/web/src/enterprise/batches/detail/changesets/HiddenExternalChangesetNode.tsx +++ b/client/web/src/enterprise/batches/detail/changesets/HiddenExternalChangesetNode.tsx @@ -20,12 +20,14 @@ export const HiddenExternalChangesetNode: React.FunctionComponent< <>
+ {/* eslint-disable-next-line no-restricted-syntax*/}
+ {/* eslint-disable-next-line no-restricted-syntax*/}
{toggleSelectAll && (
+ {/* eslint-disable-next-line no-restricted-syntax*/} Select all
diff --git a/client/web/src/enterprise/batches/preview/list/VisibleChangesetApplyPreviewNode.tsx b/client/web/src/enterprise/batches/preview/list/VisibleChangesetApplyPreviewNode.tsx index 2e33470b5fb..2292920e183 100644 --- a/client/web/src/enterprise/batches/preview/list/VisibleChangesetApplyPreviewNode.tsx +++ b/client/web/src/enterprise/batches/preview/list/VisibleChangesetApplyPreviewNode.tsx @@ -224,21 +224,25 @@ const SelectBox: React.FunctionComponent< }, [selectable, isPublishableResult]) const input = isPublishableResult.publishable ? ( + // eslint-disable-next-line no-restricted-syntax ) : ( + // eslint-disable-next-line no-restricted-syntax ) diff --git a/client/wildcard/src/components/Tooltip/Tooltip.tsx b/client/wildcard/src/components/Tooltip/Tooltip.tsx index 93437dce6cc..695db2686fc 100644 --- a/client/wildcard/src/components/Tooltip/Tooltip.tsx +++ b/client/wildcard/src/components/Tooltip/Tooltip.tsx @@ -73,7 +73,9 @@ export const Tooltip: React.FunctionComponent = ({ // NOTE: We plan to consolidate this logic with our Popover component in the future, but chose Radix first to support short-term accessibility needs. // GitHub issue: https://github.com/sourcegraph/sourcegraph/issues/36080 return ( - + // The small delayDuration helps prevent the tooltip from immediately closing when it gets triggered in the + // exact spot the arrow is overlapping the content (allows time for the cursor to move more naturally) + {trigger} { // The rest of the Tooltip components still need to be rendered for the content to correctly be shown conditionally.