Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make url input always controlled on share post bar #2200

15 changes: 9 additions & 6 deletions packages/shared/src/components/squads/SharePostBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ function SharePostBar({
const inputRef = useRef<HTMLInputElement>();
const { user } = useAuthContext();
const { openModal } = useLazyModal();
const [url, setUrl] = useState<string>(undefined);
const [url, setUrl] = useState<string>('');
const isMobile = !useMedia([mobileL.replace('@media ', '')], [true], false);
const [urlFocused, toggleUrlFocus] = useState(false);
const onSharedSuccessfully = () => {
inputRef.current.value = '';
setUrl(undefined);
setUrl('');
};

const shouldRenderReadingHistory = !urlFocused && url.length === 0;

const onOpenCreatePost = (preview: ExternalLinkPreview, link?: string) =>
openModal({
type: LazyModal.CreateSharedPost,
Expand Down Expand Up @@ -104,14 +107,14 @@ function SharePostBar({
placeholder={`Enter URL${isMobile ? '' : ' / Choose from'}`}
className={classNames(
'pl-1 tablet:min-w-[11rem] w-auto outline-none bg-theme-bg-transparent text-theme-label-primary focus:placeholder-theme-label-quaternary hover:placeholder-theme-label-primary typo-body flex-1 w-full tablet:flex-none tablet:w-auto',
url !== undefined && 'flex-1 pr-2',
!shouldRenderReadingHistory && 'flex-1 pr-2',
)}
onInput={(e) => setUrl(e.currentTarget.value)}
value={url}
onBlur={() => !url?.length && setUrl(undefined)}
onFocus={() => !url?.length && setUrl('')}
onBlur={() => toggleUrlFocus(false)}
onFocus={() => toggleUrlFocus(true)}
/>
{url === undefined && (
{shouldRenderReadingHistory && (
<ClickableText
className="hidden tablet:flex ml-1 font-bold reading-history hover:text-theme-label-primary"
inverseUnderline
Expand Down