Skip to content

Commit 4f5082c

Browse files
committed
feat: added disabled functionality
1 parent 64dfc7a commit 4f5082c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/MixInput.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
.mix-input{
22
padding: .375rem;
33
border: 1px solid #ccc;
4-
border-radius: .25rem;
54
min-height: 27px;
5+
border-radius: .25rem;
66
display: block;
77
font-size: 1rem;
88
}
99

10+
.mi-disabled{
11+
background-color: #f3f3f3;
12+
color: #666;
13+
}
14+
1015
.mix-input:focus{
1116
border: 1px solid #000;
1217
}

src/MixInput.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const MixInput = forwardRef((props: MixInputProps, ref?: ForwardedRef<MixInputRe
2222
const {
2323
onChange,
2424
value = [],
25-
// multiline,
2625
placeholder,
27-
readonly = false,
26+
disabled = false,
2827
tagClassName = 'mi-tag',
2928
editorOptions,
3029
className,
@@ -38,9 +37,10 @@ const MixInput = forwardRef((props: MixInputProps, ref?: ForwardedRef<MixInputRe
3837
const previousValueRef = useRef<string>('')
3938

4039
const editor = useEditor({
40+
editable: !disabled,
4141
immediatelyRender,
4242
editorProps: {
43-
attributes: { class: `mix-input ${className || ''}` },
43+
attributes: { class: `mix-input ${disabled ? 'mi-disabled' : ''} ${className || ''}` },
4444
},
4545
extensions: [
4646
Document,
@@ -56,12 +56,14 @@ const MixInput = forwardRef((props: MixInputProps, ref?: ForwardedRef<MixInputRe
5656
}),
5757
],
5858
onUpdate: ({ editor }) => {
59+
if (disabled) return
5960
onChange?.(editorValueToMixInputValue(editor?.getJSON()?.content || []))
6061
},
6162
...editorOptions,
6263
})
6364

6465
const insertContent = (content: MixInputValue | MixInputValue[] | MixInputValue[][]) => {
66+
if (disabled) return
6567
editor?.chain().focus().insertContent(content).run()
6668
}
6769

@@ -97,6 +99,7 @@ const MixInput = forwardRef((props: MixInputProps, ref?: ForwardedRef<MixInputRe
9799

98100
return (
99101
<EditorContent
102+
aria-disabled={disabled}
100103
editor={editor}
101104
innerRef={editorRef}
102105
{...(restProps as Omit<typeof restProps, 'ref'>)}

src/MixInputType.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ export interface MixInputProps extends HTMLAttributes<HTMLDivElement>, Omit<Edit
2222
value?: MixInputValues
2323
placeholder?: string
2424
onChange?: (value: MixInputValues) => void
25-
readonly?: boolean
25+
disabled?: boolean
2626
tagClassName?: string
2727
editorOptions?: UseEditorOptions
2828
tagAttrs?: Record<string, string | undefined>
2929
tagView?: (props: NodeViewProps) => React.ReactNode
3030
immediatelyRender?: boolean
3131
ref?: React.Ref<MixInputRef>
32-
// multiline?: boolean
3332
}
3433

3534
export interface MixInputRef {

0 commit comments

Comments
 (0)