mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-10-18 19:10:45 +08:00
committed by
Rūdolfs Ošiņš
parent
ba5e571337
commit
e97af99286
@@ -105,6 +105,12 @@
|
|||||||
? submitActiveVariant
|
? submitActiveVariant
|
||||||
: submitVariant,
|
: submitVariant,
|
||||||
);
|
);
|
||||||
|
const submitDisabled = $derived(
|
||||||
|
!isValid() ||
|
||||||
|
submitInProgress ||
|
||||||
|
disableSubmit ||
|
||||||
|
(disallowEmptyBody && body.trim() === ""),
|
||||||
|
);
|
||||||
|
|
||||||
let selectionStart = $state(body.length);
|
let selectionStart = $state(body.length);
|
||||||
let selectionEnd = $state(body.length);
|
let selectionEnd = $state(body.length);
|
||||||
@@ -287,6 +293,13 @@
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function triggerSubmit() {
|
||||||
|
if (submitDisabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
submitFn();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -517,10 +530,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant={effectiveSubmitVariant}
|
variant={effectiveSubmitVariant}
|
||||||
title={emptyBodyTooltip}
|
title={emptyBodyTooltip}
|
||||||
disabled={!isValid() ||
|
disabled={submitDisabled}
|
||||||
submitInProgress ||
|
|
||||||
disableSubmit ||
|
|
||||||
(disallowEmptyBody && body.trim() === "")}
|
|
||||||
onclick={submitFn}>
|
onclick={submitFn}>
|
||||||
{#if submitInProgress}
|
{#if submitInProgress}
|
||||||
Saving…
|
Saving…
|
||||||
@@ -600,10 +610,7 @@
|
|||||||
<Button
|
<Button
|
||||||
variant={effectiveSubmitVariant}
|
variant={effectiveSubmitVariant}
|
||||||
title={emptyBodyTooltip}
|
title={emptyBodyTooltip}
|
||||||
disabled={!isValid() ||
|
disabled={submitDisabled}
|
||||||
submitInProgress ||
|
|
||||||
disableSubmit ||
|
|
||||||
(disallowEmptyBody && body.trim() === "")}
|
|
||||||
onclick={submitFn}>
|
onclick={submitFn}>
|
||||||
{#if submitInProgress}
|
{#if submitInProgress}
|
||||||
Saving…
|
Saving…
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
import * as utils from "@app/lib/utils";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
autoselect?: boolean;
|
autoselect?: boolean;
|
||||||
@@ -15,6 +17,7 @@
|
|||||||
onFocus?: () => void;
|
onFocus?: () => void;
|
||||||
onBlur?: () => void;
|
onBlur?: () => void;
|
||||||
onSubmit?: () => void;
|
onSubmit?: () => void;
|
||||||
|
onModifierSubmit?: () => void;
|
||||||
oninput?: FormEventHandler<HTMLInputElement>;
|
oninput?: FormEventHandler<HTMLInputElement>;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
@@ -35,6 +38,7 @@
|
|||||||
onFocus,
|
onFocus,
|
||||||
onBlur,
|
onBlur,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onModifierSubmit,
|
||||||
oninput,
|
oninput,
|
||||||
placeholder,
|
placeholder,
|
||||||
type = "text",
|
type = "text",
|
||||||
@@ -65,6 +69,13 @@
|
|||||||
|
|
||||||
function handleKeydown(event: KeyboardEvent) {
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
const auxiliarKey = utils.isMac() ? event.metaKey : event.ctrlKey;
|
||||||
|
if (auxiliarKey && event.key === "Enter" && onModifierSubmit) {
|
||||||
|
event.preventDefault();
|
||||||
|
onModifierSubmit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === "Enter" && valid && onSubmit) {
|
if (event.key === "Enter" && valid && onSubmit) {
|
||||||
onSubmit();
|
onSubmit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
const { repo }: Props = $props();
|
const { repo }: Props = $props();
|
||||||
|
|
||||||
|
let commentBox: ExtendedTextarea | undefined = $state();
|
||||||
let preview = $state(false);
|
let preview = $state(false);
|
||||||
let title = $state("");
|
let title = $state("");
|
||||||
let body = $state("");
|
let body = $state("");
|
||||||
@@ -155,10 +156,12 @@
|
|||||||
placeholder="Title"
|
placeholder="Title"
|
||||||
autofocus
|
autofocus
|
||||||
onDismiss={hide}
|
onDismiss={hide}
|
||||||
|
onModifierSubmit={() => commentBox?.triggerSubmit()}
|
||||||
bind:value={title} />
|
bind:value={title} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<ExtendedTextarea
|
<ExtendedTextarea
|
||||||
|
bind:this={commentBox}
|
||||||
textAreaSize="fixed-height"
|
textAreaSize="fixed-height"
|
||||||
disableSubmit={title.trim() === ""}
|
disableSubmit={title.trim() === ""}
|
||||||
disallowEmptyBody
|
disallowEmptyBody
|
||||||
|
|||||||
Reference in New Issue
Block a user