Merge branch 'accessible-compose' into 'develop'
Add form element on compose area See merge request soapbox-pub/soapbox!1870
This commit is contained in:
commit
479c6e8e85
|
@ -40,6 +40,8 @@ interface IHStack {
|
|||
space?: keyof typeof spaces
|
||||
/** Whether to let the flexbox grow. */
|
||||
grow?: boolean
|
||||
/** HTML element to use for container. */
|
||||
element?: keyof JSX.IntrinsicElements,
|
||||
/** Extra CSS styles for the <div> */
|
||||
style?: React.CSSProperties
|
||||
/** Whether to let the flexbox wrap onto multiple lines. */
|
||||
|
@ -48,10 +50,12 @@ interface IHStack {
|
|||
|
||||
/** Horizontal row of child elements. */
|
||||
const HStack = forwardRef<HTMLDivElement, IHStack>((props, ref) => {
|
||||
const { space, alignItems, grow, justifyContent, wrap, className, ...filteredProps } = props;
|
||||
const { space, alignItems, justifyContent, className, grow, element = 'div', wrap, ...filteredProps } = props;
|
||||
|
||||
const Elem = element as 'div';
|
||||
|
||||
return (
|
||||
<div
|
||||
<Elem
|
||||
{...filteredProps}
|
||||
ref={ref}
|
||||
className={classNames('flex', {
|
||||
|
|
|
@ -23,24 +23,28 @@ const alignItemsOptions = {
|
|||
};
|
||||
|
||||
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/** Size of the gap between elements. */
|
||||
space?: keyof typeof spaces
|
||||
/** Horizontal alignment of children. */
|
||||
alignItems?: 'center'
|
||||
/** Extra class names on the element. */
|
||||
className?: string
|
||||
/** Vertical alignment of children. */
|
||||
justifyContent?: keyof typeof justifyContentOptions
|
||||
/** Extra class names on the <div> element. */
|
||||
className?: string
|
||||
/** Size of the gap between elements. */
|
||||
space?: keyof typeof spaces
|
||||
/** Whether to let the flexbox grow. */
|
||||
grow?: boolean
|
||||
/** HTML element to use for container. */
|
||||
element?: keyof JSX.IntrinsicElements,
|
||||
}
|
||||
|
||||
/** Vertical stack of child elements. */
|
||||
const Stack = React.forwardRef<HTMLDivElement, IStack>((props, ref: React.LegacyRef<HTMLDivElement> | undefined) => {
|
||||
const { space, alignItems, justifyContent, className, grow, ...filteredProps } = props;
|
||||
const { space, alignItems, justifyContent, className, grow, element = 'div', ...filteredProps } = props;
|
||||
|
||||
const Elem = element as 'div';
|
||||
|
||||
return (
|
||||
<div
|
||||
<Elem
|
||||
{...filteredProps}
|
||||
ref={ref}
|
||||
className={classNames('flex flex-col', {
|
||||
|
|
|
@ -132,7 +132,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
|||
setComposeFocused(true);
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const handleSubmit = (e?: React.FormEvent<Element>) => {
|
||||
if (text !== autosuggestTextareaRef.current?.textarea?.value) {
|
||||
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
|
||||
// Update the state to match the current text
|
||||
|
@ -142,6 +142,10 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
|||
// Submit disabled:
|
||||
const fulltext = [spoilerText, countableText(text)].join('');
|
||||
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxTootChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
|
||||
return;
|
||||
}
|
||||
|
@ -261,7 +265,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
|||
}
|
||||
|
||||
return (
|
||||
<Stack className='w-full' space={4} ref={formRef} onClick={handleClick}>
|
||||
<Stack className='w-full' space={4} ref={formRef} onClick={handleClick} element='form' onSubmit={handleSubmit}>
|
||||
{scheduledStatusCount > 0 && (
|
||||
<Warning
|
||||
message={(
|
||||
|
@ -339,7 +343,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
|
|||
</div>
|
||||
)}
|
||||
|
||||
<Button theme='primary' text={publishText} onClick={handleSubmit} disabled={disabledButton} />
|
||||
<Button type='submit' theme='primary' text={publishText} disabled={disabledButton} />
|
||||
</div>
|
||||
</div>
|
||||
</Stack>
|
||||
|
|
|
@ -168,7 +168,7 @@ const PollForm: React.FC<IPollForm> = ({ composeId }) => {
|
|||
|
||||
<Divider />
|
||||
|
||||
<button onClick={handleToggleMultiple} className='text-left'>
|
||||
<button type='button' onClick={handleToggleMultiple} className='text-left'>
|
||||
<HStack alignItems='center' justifyContent='between'>
|
||||
<Stack>
|
||||
<Text weight='medium'>
|
||||
|
@ -197,7 +197,7 @@ const PollForm: React.FC<IPollForm> = ({ composeId }) => {
|
|||
|
||||
{/* Remove Poll */}
|
||||
<div className='text-center'>
|
||||
<button className='text-danger-500' onClick={onRemovePoll}>
|
||||
<button type='button' className='text-danger-500' onClick={onRemovePoll}>
|
||||
{intl.formatMessage(messages.removePoll)}
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -68,7 +68,7 @@ const SpoilerInput = React.forwardRef<AutosuggestInput, ISpoilerInput>(({
|
|||
/>
|
||||
|
||||
<div className='text-center'>
|
||||
<button className='text-danger-500' onClick={handleRemove}>
|
||||
<button type='button' className='text-danger-500' onClick={handleRemove}>
|
||||
{intl.formatMessage(messages.remove)}
|
||||
</button>
|
||||
</div>
|
||||
|
@ -77,4 +77,4 @@ const SpoilerInput = React.forwardRef<AutosuggestInput, ISpoilerInput>(({
|
|||
);
|
||||
});
|
||||
|
||||
export default SpoilerInput;
|
||||
export default SpoilerInput;
|
||||
|
|
Loading…
Reference in New Issue