From 8b0c4fff9bc7f4be556f2eb53b3ebd1912453353 Mon Sep 17 00:00:00 2001 From: neopostmodern Date: Sun, 30 Apr 2023 05:22:04 +0200 Subject: [PATCH] fix(client): proper read-only form field props and styles --- .../src/renderer/components/fields/LinkNameField.tsx | 6 ++++-- client/src/renderer/components/fields/UrlField.tsx | 11 +++++++++-- client/src/renderer/components/formComponents.tsx | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/client/src/renderer/components/fields/LinkNameField.tsx b/client/src/renderer/components/fields/LinkNameField.tsx index 992f567..962051e 100644 --- a/client/src/renderer/components/fields/LinkNameField.tsx +++ b/client/src/renderer/components/fields/LinkNameField.tsx @@ -44,7 +44,7 @@ const LinkNameField: React.FC = ({ url, name, linkId, - readOnly = false, + readOnly: forceReadOnly = false, }) => { const { setValue, getValues } = useFormContext(); @@ -65,6 +65,7 @@ const LinkNameField: React.FC = ({ ); const isOnline = useIsOnline(); + const readOnly = !isOnline || forceReadOnly; const suggestions = titleSuggestionsQuery.state === DataState.DATA ? titleSuggestionsQuery.data.titleSuggestions @@ -90,6 +91,7 @@ const LinkNameField: React.FC = ({ disableClearable freeSolo openOnFocus + readOnly={readOnly} renderInput={({ ...params }) => ( = ({ fetchTitleSuggestions(); }} label="Title" - disabled={!isOnline || readOnly} + InputProps={{ readOnly }} /> )} renderOption={(props, suggestion) => { diff --git a/client/src/renderer/components/fields/UrlField.tsx b/client/src/renderer/components/fields/UrlField.tsx index ee84e16..8b715fd 100644 --- a/client/src/renderer/components/fields/UrlField.tsx +++ b/client/src/renderer/components/fields/UrlField.tsx @@ -2,6 +2,7 @@ import { ContentCopy, Launch, Share } from '@mui/icons-material'; import { Box, IconButton, Tooltip } from '@mui/material'; import React from 'react'; import { useFormContext } from 'react-hook-form'; +import useIsOnline from '../../hooks/useIsOnline'; import { openInDefaultBrowser, shareUrl } from '../../utils/openWith'; import { StructureTextField } from '../formComponents'; @@ -10,16 +11,22 @@ interface UrlFieldProps { readOnly?: boolean; } -const UrlField: React.FC = ({ name, readOnly = false }) => { +const UrlField: React.FC = ({ + name, + readOnly: forceReadOnly = false, +}) => { const { watch, register, getValues, formState } = useFormContext(); + const isOnline = useIsOnline(); + const readOnly = !isOnline || forceReadOnly; + return ( <> diff --git a/client/src/renderer/components/formComponents.tsx b/client/src/renderer/components/formComponents.tsx index 1fcdaeb..d2b73ef 100644 --- a/client/src/renderer/components/formComponents.tsx +++ b/client/src/renderer/components/formComponents.tsx @@ -19,6 +19,10 @@ export const StructureTextField = styled(TextField).attrs({ ${FORM_SUBHEADER_STYLES} font-size: 1.07rem; // 0.8rem / 0.75 scale } + .MuiInputBase-readOnly:after, + .MuiInputBase-readOnly:before { + border-bottom-color: transparent !important; + } `; export const NameInput = styled(StructureTextField)`