From 77daa458cf720f6cc21e4d63df3249cdd9fe8452 Mon Sep 17 00:00:00 2001 From: SatsAllDay <128755788+SatsAllDay@users.noreply.github.com> Date: Mon, 11 Sep 2023 20:20:44 -0400 Subject: [PATCH] Visual Character counter for post titles, poll options (#466) * Indicate how many chars remain for title field and poll options Live counter update to help authors know how many more chars they have to use in their post titles, and also poll options * Use InputInner for consistency * Refactor to reuse title hint across all forms * Character(s) * Move maxLength hint impl to InputInner, per PR feedback --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> --- components/bounty-form.js | 10 +++++++++- components/discussion-form.js | 2 ++ components/form.js | 6 ++++++ components/job-form.js | 2 ++ components/link-form.js | 2 ++ components/poll-form.js | 4 +++- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/components/bounty-form.js b/components/bounty-form.js index 7d0696e3..41c8da17 100644 --- a/components/bounty-form.js +++ b/components/bounty-form.js @@ -10,6 +10,7 @@ import { SubSelectInitial } from './sub-select-form' import CancelButton from './cancel-button' import { useCallback } from 'react' import { normalizeForwards } from '../lib/form' +import { MAX_TITLE_LENGTH } from '../lib/constants' export function BountyForm ({ item, @@ -98,7 +99,14 @@ export function BountyForm ({ storageKeyPrefix={item ? undefined : 'bounty'} > {children} - + sats} diff --git a/components/discussion-form.js b/components/discussion-form.js index 08b15575..00b5ec79 100644 --- a/components/discussion-form.js +++ b/components/discussion-form.js @@ -14,6 +14,7 @@ import { SubSelectInitial } from './sub-select-form' import CancelButton from './cancel-button' import { useCallback } from 'react' import { normalizeForwards } from '../lib/form' +import { MAX_TITLE_LENGTH } from '../lib/constants' export function DiscussionForm ({ item, sub, editThreshold, titleLabel = 'title', @@ -101,6 +102,7 @@ export function DiscussionForm ({ }) } }} + maxLength={MAX_TITLE_LENGTH} /> )} + {props.maxLength && ( + + {`${numWithUnits(props.maxLength - (field.value || '').length, { abbreviate: false, unitSingular: 'character', unitPlural: 'characters' })} remaining`} + + )} ) } diff --git a/components/job-form.js b/components/job-form.js index a710fb3b..938c515b 100644 --- a/components/job-form.js +++ b/components/job-form.js @@ -17,6 +17,7 @@ import Avatar from './avatar' import ActionTooltip from './action-tooltip' import { jobSchema } from '../lib/validate' import CancelButton from './cancel-button' +import { MAX_TITLE_LENGTH } from '../lib/constants' function satsMin2Mo (minute) { return minute * 30 * 24 * 60 @@ -116,6 +117,7 @@ export default function JobForm ({ item, sub }) { required autoFocus clear + maxLength={MAX_TITLE_LENGTH} /> : null} + maxLength={MAX_POLL_CHOICE_LENGTH} />