Format tag input with #

environments/review-group-fixe-2vkaad/deployments/3363
Chewbacca 2023-05-11 14:28:44 -04:00
rodzic 6ab41eb899
commit 93c67c863a
1 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
import React from 'react'; import React, { useMemo } from 'react';
import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
import { Input, Streamfield } from 'soapbox/components/ui'; import { Input, Streamfield } from 'soapbox/components/ui';
@ -36,15 +36,19 @@ const GroupTagsField: React.FC<IGroupTagsField> = ({ tags, onChange, onAddItem,
const HashtagField: StreamfieldComponent<string> = ({ value, onChange, autoFocus = false }) => { const HashtagField: StreamfieldComponent<string> = ({ value, onChange, autoFocus = false }) => {
const intl = useIntl(); const intl = useIntl();
const formattedValue = useMemo(() => {
return `#${value}`;
}, [value]);
const handleChange: React.ChangeEventHandler<HTMLInputElement> = ({ target }) => { const handleChange: React.ChangeEventHandler<HTMLInputElement> = ({ target }) => {
onChange(target.value); onChange(target.value.replace('#', ''));
}; };
return ( return (
<Input <Input
outerClassName='w-full' outerClassName='w-full'
type='text' type='text'
value={value} value={formattedValue}
onChange={handleChange} onChange={handleChange}
placeholder={intl.formatMessage(messages.hashtagPlaceholder)} placeholder={intl.formatMessage(messages.hashtagPlaceholder)}
autoFocus={autoFocus} autoFocus={autoFocus}