-
Notifications
You must be signed in to change notification settings - Fork 7
/
fast_textarea_input.ts
135 lines (114 loc) · 5.25 KB
/
fast_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {TextAreaInput} from "@bokehjs/models/widgets/textarea_input"
import {InputWidgetView} from "@bokehjs/models/widgets/input_widget"
import * as p from "@bokehjs/core/properties"
// I tried to inherit from TextAreaInputView but I could not
// get it working. It created two textareainputs.
export class FastTextAreaInputView extends InputWidgetView {
model: FastTextAreaInput
protected input_el: HTMLTextAreaElement
public get input_el_any() : any {
return <any>this.input_el;
}
connect_signals(): void {
super.connect_signals()
this.connect(this.model.properties.name.change, () => this.input_el.name = this.model.name ?? "")
this.connect(this.model.properties.value.change, () => {this.input_el.value = this.model.value;})
this.connect(this.model.properties.disabled.change, () => this.input_el.disabled = this.model.disabled)
this.connect(this.model.properties.placeholder.change, () => this.input_el.placeholder = this.model.placeholder)
this.connect(this.model.properties.rows.change, () => this.input_el.rows = this.model.rows)
this.connect(this.model.properties.cols.change, () => this.input_el.cols = this.model.cols)
this.connect(this.model.properties.max_length.change, () => this.input_el_any.setAttribute("maxlength", this.model.max_length))
this.connect(this.model.properties.appearance.change, () => this.input_el_any.appearance = this.model.appearance)
this.connect(this.model.properties.autofocus.change, () => this.input_el_any.autofocus = this.model.autofocus)
this.connect(this.model.properties.resize.change, () => this.input_el_any.resize = this.model.resize)
this.connect(this.model.properties.spellcheck.change, () => this.input_el_any.spellcheck = this.model.spellcheck)
this.connect(this.model.properties.min_length.change, () => this.input_el_any.setAttribute("minlength", this.model.min_length))
this.connect(this.model.properties.required.change, () => this.input_el_any.required = this.model.required)
// Could not get readonly working as a property.
// https://github.com/microsoft/fast/issues/3852
this.connect(this.model.properties.readonly.change, () => {
if (this.model.readonly===true){
this.input_el_any.setAttribute("readonly", "")
} else {
this.input_el_any.removeAttribute("readonly")
}
})
}
render(): void {
super.render()
const fastTextArea = <any>document.createElement("fast-text-area")
this.input_el = <HTMLTextAreaElement>fastTextArea;
this.input_el.className="bk-fast-input"
this.input_el.addEventListener("change", () => this.change_input())
this.group_el.appendChild(this.input_el)
// For some unknown reason we need to set these properties after the above
// Otherwise for example the value is reset to ""
fastTextArea.name = this.model.name;
fastTextArea.value = this.model.value;
fastTextArea.disabled = this.model.disabled;
fastTextArea.placeholder = this.model.placeholder;
fastTextArea.cols = this.model.cols;
fastTextArea.rows = this.model.rows;
if (this.model.max_length!=null)
fastTextArea.setAttribute("maxlength", this.model.max_length);
fastTextArea.appearance = this.model.appearance;
fastTextArea.autofocus = this.model.autofocus;
fastTextArea.resize = this.model.resize;
fastTextArea.spellcheck = this.model.spellcheck;
if (this.model.min_length!=null)
fastTextArea.setAttribute("minlength", this.model.min_length);
fastTextArea.required = this.model.required;
if (this.model.readonly===true)
fastTextArea.setAttribute("readonly", "");
}
change_input(): void {
this.model.value = this.input_el.value
super.change_input()
}
}
export namespace FastTextAreaInput {
export type Attrs = p.AttrsOf<Props>
export type Props = TextAreaInput.Props & {
// name inherited
// value inherited
// placeholder inherited
// max_length inherited
// disabled inherited
// cols inherited
// rows inherited
appearance: p.Property<string>;
autofocus: p.Property<boolean>;
resize: p.Property<string>;
spellcheck: p.Property<boolean>;
min_length: p.Property<number>;
required: p.Property<boolean>;
readonly: p.Property<boolean>;
}
}
export interface FastTextAreaInput extends FastTextAreaInput.Attrs {}
export class FastTextAreaInput extends TextAreaInput {
properties: FastTextAreaInput.Props
constructor(attrs?: Partial<FastTextAreaInput.Attrs>) {
super(attrs)
}
static __module__ = "awesome_panel_extensions.bokeh_extensions.fast.fast_textarea_input"
static init_FastTextAreaInput(): void {
this.prototype.default_view = FastTextAreaInputView
this.define<FastTextAreaInput.Props>({
// name inherited
// value inherited
// placeholder inherited
// max_length inherited
// disabled inherited
// cols inherited
// rows inherited
appearance: [p.String, ],
autofocus: [p.Boolean, ],
resize: [p.String, ],
spellcheck: [p.Boolean, ],
min_length: [p.Number, ],
required: [p.Boolean, ],
readonly: [p.Boolean, ],
})
}
}