Skip to content

Commit 97e75f9

Browse files
committed
Allow multiple inlineStyles to be returned by customInlineFn sstur#155
1 parent 7318dce commit 97e75f9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/draft-js-import-element/src/__tests__/stateFromElement-test.js

+35
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,41 @@ describe('stateFromElement', () => {
146146
});
147147
});
148148

149+
it('should return multiple style from customInlineFn', () => {
150+
let element = new ElementNode('div', [], [
151+
new ElementNode(
152+
'span',
153+
[{style: 'font-family', value: 'sans-serif'},{style: 'font-size', value: '12px'},],
154+
[new TextNode('Hello')]
155+
)
156+
]);
157+
let options = {
158+
customInlineFn(el, {Style}) {
159+
if (el.tagName === 'SPAN') {
160+
return Style(['CUSTOM_STYLE_1', 'CUSTOM_STYLE_2']);
161+
}
162+
},
163+
};
164+
let contentState = stateFromElement(element, options);
165+
let rawContentState = removeBlockKeys(convertToRaw(contentState));
166+
expect(rawContentState).toEqual({
167+
entityMap: {},
168+
blocks: [
169+
{
170+
text: 'Hello',
171+
type: 'unstyled',
172+
depth: 0,
173+
inlineStyleRanges: [
174+
{offset: 0, length: 5, style: 'CUSTOM_STYLE_1'},
175+
{offset: 0, length: 5, style: 'CUSTOM_STYLE_2'}
176+
],
177+
entityRanges: [],
178+
data: {},
179+
},
180+
],
181+
});
182+
});
183+
149184
it('should support option elementStyles', () => {
150185
let textNode = new TextNode('Superscript');
151186
let element = new ElementNode('sup', [], [textNode]);

packages/draft-js-import-element/src/stateFromElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class ContentGenerator {
347347
if (customInline != null) {
348348
switch (customInline.type) {
349349
case 'STYLE': {
350-
style = style.add(customInline.style);
350+
[].concat(customInline.style).forEach(customStyle => style = style.add(customStyle));
351351
break;
352352
}
353353
case 'ENTITY': {

0 commit comments

Comments
 (0)