kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Format tag input with #
rodzic
6ab41eb899
commit
93c67c863a
|
@ -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}
|
||||||
|
|
Ładowanie…
Reference in New Issue