Implement getTextLabel on draftail widget

pull/6951/head
Matt Westcott 2021-02-20 02:53:33 +00:00
rodzic b219b60f95
commit 0fa8508232
1 zmienionych plików z 17 dodań i 0 usunięć

Wyświetl plik

@ -137,6 +137,23 @@ class DraftailRichTextArea {
setState() {
throw new Error('DraftailRichTextArea.setState is not implemented');
},
getTextLabel(opts) {
const maxLength = opts && opts.maxLength;
if (!input.value) return '';
const value = JSON.parse(input.value);
if (!value || !value.blocks) return '';
let result = '';
for (const block of value.blocks) {
if (block.text) {
result += (result ? ' ' + block.text : block.text);
if (maxLength && result.length > maxLength) {
return result.substring(0, maxLength - 1) + '…';
}
}
}
return result;
},
focus: () => {
input.draftailEditor.focus();
},