-
-
Notifications
You must be signed in to change notification settings - Fork 477
/
textarea_input.ts
63 lines (49 loc) · 1.66 KB
/
textarea_input.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {TextAreaInput as BkTextAreaInput, TextAreaInputView as BkTextAreaInputView} from "@bokehjs/models/widgets/textarea_input"
import type * as p from "@bokehjs/core/properties"
export class TextAreaInputView extends BkTextAreaInputView {
declare model: TextAreaInput
override connect_signals(): void {
super.connect_signals()
const {value, max_rows} = this.model.properties
this.on_change([max_rows, value], () => this.update_rows())
}
update_rows(): void {
if (!this.model.auto_grow) {
return
}
// Use this.el directly to access the textarea element
const textarea = this.input_el
const textLines = textarea.value.split("\n")
const numRows = Math.max(textLines.length, this.model.rows, 1)
textarea.rows = Math.min(numRows, this.model.max_rows || Infinity)
}
override render(): void {
super.render()
this.update_rows()
this.el.addEventListener("input", () => {
this.update_rows()
})
}
}
export namespace TextAreaInput {
export type Attrs = p.AttrsOf<Props>
export type Props = BkTextAreaInput.Props & {
auto_grow: p.Property<boolean>
max_rows: p.Property<number | null>
}
}
export interface TextAreaInput extends TextAreaInput.Attrs { }
export class TextAreaInput extends BkTextAreaInput {
declare properties: TextAreaInput.Props
constructor(attrs?: Partial<TextAreaInput.Attrs>) {
super(attrs)
}
static override __module__ = "panel.models.widgets"
static {
this.prototype.default_view = TextAreaInputView
this.define<TextAreaInput.Props>(({Bool, Int, Nullable}) => ({
auto_grow: [ Bool, false ],
max_rows: [ Nullable(Int), null ],
}))
}
}