Skip to content

Commit 87b396e

Browse files
authored
Merge pull request #3468 from plotly/feature/dcc-refactor-textarea-tooltip
dcc redesign: refactor `TextArea` and `Tooltip`
2 parents 504c65d + b189e2c commit 87b396e

File tree

8 files changed

+519
-549
lines changed

8 files changed

+519
-549
lines changed

components/dash-core-components/src/components/Textarea.react.js

Lines changed: 0 additions & 287 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* eslint-disable no-unused-vars */
2+
import React from 'react';
3+
import {pick} from 'ramda';
4+
import {PersistedProps, PersistenceTypes, TextAreaProps} from '../types';
5+
import './css/textarea.css';
6+
7+
const textAreaProps = [
8+
'id',
9+
'cols',
10+
'rows',
11+
'minLength',
12+
'maxLength',
13+
'contentEditable',
14+
'tabIndex',
15+
'form',
16+
'name',
17+
'placeholder',
18+
'wrap',
19+
'accessKey',
20+
'contextMenu',
21+
'dir',
22+
'draggable',
23+
'lang',
24+
'spellCheck',
25+
'style',
26+
'title',
27+
] as const;
28+
29+
/**
30+
* A basic HTML textarea for entering multiline text.
31+
*
32+
*/
33+
const Textarea = ({
34+
setProps,
35+
n_blur = 0,
36+
n_blur_timestamp = -1,
37+
n_clicks = 0,
38+
n_clicks_timestamp = -1,
39+
...props
40+
}: TextAreaProps) => {
41+
const ctx = window.dash_component_api.useDashContext();
42+
const isLoading = ctx.useLoading();
43+
44+
return (
45+
<textarea
46+
data-dash-is-loading={isLoading || undefined}
47+
className={'dash-textarea ' + props.className}
48+
value={props.value}
49+
disabled={!!props.disabled}
50+
readOnly={!!props.readOnly}
51+
required={!!props.required}
52+
autoFocus={!!props.autoFocus}
53+
hidden={!!props.hidden}
54+
onChange={e => {
55+
setProps({value: e.target.value});
56+
}}
57+
onBlur={() => {
58+
setProps({
59+
n_blur: n_blur + 1,
60+
n_blur_timestamp: Date.now(),
61+
});
62+
}}
63+
onClick={() => {
64+
setProps({
65+
n_clicks: n_clicks + 1,
66+
n_clicks_timestamp: Date.now(),
67+
});
68+
}}
69+
{...pick(textAreaProps, props)}
70+
/>
71+
);
72+
};
73+
74+
Textarea.dashPersistence = {
75+
persisted_props: [PersistedProps.value],
76+
persistence_type: PersistenceTypes.local,
77+
};
78+
79+
export default Textarea;

0 commit comments

Comments
 (0)