From be32a0c1a081f2fba417c35acb8e41f84c2ca336 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Mar 2023 15:36:53 -0500 Subject: [PATCH 1/3] Textarea: add a character counter --- CHANGELOG.md | 1 + .../components/ui/textarea/textarea.tsx | 52 ++++++++++++++----- .../components/registration-form.tsx | 4 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e04be802..b8df9bb65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Posts: Support posts filtering on recent Mastodon versions - Reactions: Support custom emoji reactions - Compatbility: Support Mastodon v2 timeline filters. +- UI: added a character counter to some textareas. ### Changed - Posts: truncate Nostr pubkeys in reply mentions. diff --git a/app/soapbox/components/ui/textarea/textarea.tsx b/app/soapbox/components/ui/textarea/textarea.tsx index 03ddda81d..b5c252ffb 100644 --- a/app/soapbox/components/ui/textarea/textarea.tsx +++ b/app/soapbox/components/ui/textarea/textarea.tsx @@ -1,5 +1,9 @@ import clsx from 'clsx'; import React, { useState } from 'react'; +import { FormattedMessage } from 'react-intl'; + +import Stack from '../stack/stack'; +import Text from '../text/text'; interface ITextarea extends Pick, 'maxLength' | 'onChange' | 'onKeyDown' | 'onPaste' | 'required' | 'disabled' | 'rows' | 'readOnly'> { /** Put the cursor into the input on mount. */ @@ -28,6 +32,8 @@ interface ITextarea extends Pick) => { + const length = value?.length || 0; const [rows, setRows] = useState(autoGrow ? 1 : 4); const handleChange = (event: React.ChangeEvent) => { @@ -70,20 +79,35 @@ const Textarea = React.forwardRef(({ }; return ( -