Skip to content

Commit ef29db0

Browse files
committed
Skip rendering ListNestingStyles when below the default Draft.js max depth
1 parent 478d5be commit ef29db0

File tree

3 files changed

+233
-8
lines changed

3 files changed

+233
-8
lines changed

src/components/DraftailEditor.test.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,18 @@ describe("DraftailEditor", () => {
299299
});
300300
});
301301

302-
it("#maxListNesting", () => {
303-
expect(
304-
shallowNoLifecycle(<DraftailEditor maxListNesting={6} />),
305-
).toMatchSnapshot();
302+
describe("#maxListNesting", () => {
303+
it("renders when 6", () => {
304+
expect(
305+
shallowNoLifecycle(<DraftailEditor maxListNesting={6} />),
306+
).toMatchSnapshot();
307+
});
308+
309+
it("skips when 1", () => {
310+
expect(
311+
shallowNoLifecycle(<DraftailEditor maxListNesting={1} />),
312+
).toMatchSnapshot();
313+
});
306314
});
307315

308316
describe("#onSave", () => {

src/components/DraftailEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { condenseBlocks } from "draftjs-filters";
1414
// @ts-ignore
1515
import Editor from "draft-js-plugins-editor";
1616
import {
17+
DRAFT_DEFAULT_MAX_DEPTH,
1718
registerCopySource,
1819
handleDraftEditorPastedText,
1920
createEditorStateFromRaw,
@@ -1140,7 +1141,9 @@ class DraftailEditor extends Component<
11401141
placeholder={placeholder}
11411142
/>
11421143

1143-
<ListNestingStyles max={maxListNesting} />
1144+
{maxListNesting > DRAFT_DEFAULT_MAX_DEPTH ? (
1145+
<ListNestingStyles max={maxListNesting} />
1146+
) : null}
11441147
</div>
11451148
);
11461149
}

src/components/__snapshots__/DraftailEditor.test.tsx.snap

Lines changed: 217 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`DraftailEditor #maxListNesting 1`] = `
3+
exports[`DraftailEditor #maxListNesting renders when 6 1`] = `
44
<div
55
className="Draftail-Editor"
66
data-draftail-editor={true}
@@ -220,7 +220,7 @@ exports[`DraftailEditor #maxListNesting 1`] = `
220220
</div>
221221
`;
222222

223-
exports[`DraftailEditor empty 1`] = `
223+
exports[`DraftailEditor #maxListNesting skips when 1 1`] = `
224224
<div
225225
className="Draftail-Editor"
226226
data-draftail-editor={true}
@@ -434,8 +434,222 @@ exports[`DraftailEditor empty 1`] = `
434434
blockTypes={Array []}
435435
placeholder={null}
436436
/>
437+
</div>
438+
`;
439+
440+
exports[`DraftailEditor empty 1`] = `
441+
<div
442+
className="Draftail-Editor"
443+
data-draftail-editor={true}
444+
>
445+
<Toolbar
446+
addBR={[Function]}
447+
addHR={[Function]}
448+
blockTypes={Array []}
449+
commands={false}
450+
controls={Array []}
451+
currentBlock="unstyled"
452+
currentBlockKey="a"
453+
currentStyles={Immutable.OrderedSet []}
454+
enableHorizontalRule={false}
455+
enableLineBreak={false}
456+
entityTypes={Array []}
457+
focus={[Function]}
458+
getEditorState={[Function]}
459+
inlineStyles={Array []}
460+
onChange={[Function]}
461+
onCompleteSource={[Function]}
462+
onRequestSource={[Function]}
463+
onUndoRedo={[Function]}
464+
readOnly={false}
465+
showRedoControl={false}
466+
showUndoControl={false}
467+
toggleBlockType={[Function]}
468+
toggleInlineStyle={[Function]}
469+
/>
470+
<PluginEditor
471+
ariaDescribedBy={null}
472+
ariaExpanded={null}
473+
ariaLabel={null}
474+
ariaLabelledBy={null}
475+
ariaMultiline={true}
476+
ariaOwneeID={null}
477+
ariaRequired={null}
478+
autoCapitalize={null}
479+
autoComplete={null}
480+
autoCorrect={null}
481+
blockRenderMap={
482+
Immutable.Map {
483+
"ordered-list-item": Object {
484+
"element": "li",
485+
"wrapper": <ol
486+
className="public-DraftStyleDefault-ol"
487+
/>,
488+
},
489+
"header-six": Object {
490+
"element": "h6",
491+
},
492+
"header-four": Object {
493+
"element": "h4",
494+
},
495+
"header-one": Object {
496+
"element": "h1",
497+
},
498+
"unordered-list-item": Object {
499+
"element": "li",
500+
"wrapper": <ul
501+
className="public-DraftStyleDefault-ul"
502+
/>,
503+
},
504+
"atomic": Object {
505+
"element": "figure",
506+
},
507+
"unstyled": Object {
508+
"aliasedElements": Array [
509+
"p",
510+
],
511+
"element": "div",
512+
},
513+
"header-two": Object {
514+
"element": "h2",
515+
},
516+
"code-block": Object {
517+
"element": "pre",
518+
"wrapper": <pre
519+
className="public-DraftStyleDefault-pre"
520+
/>,
521+
},
522+
"blockquote": Object {
523+
"element": "blockquote",
524+
},
525+
"header-five": Object {
526+
"element": "h5",
527+
},
528+
"header-three": Object {
529+
"element": "h3",
530+
},
531+
}
532+
}
533+
blockRendererFn={[Function]}
534+
blockStyleFn={[Function]}
535+
customStyleMap={Object {}}
536+
decorators={Array []}
537+
defaultBlockRenderMap={true}
538+
defaultKeyBindings={false}
539+
defaultKeyCommands={true}
540+
editorState={
541+
EditorState {
542+
"_immutable": Immutable.Record {
543+
"allowUndo": true,
544+
"currentContent": Immutable.Record {
545+
"entityMap": Object {
546+
"__add": [Function],
547+
"__create": [Function],
548+
"__get": [Function],
549+
"__getLastCreatedEntityKey": [Function],
550+
"__mergeData": [Function],
551+
"__replaceData": [Function],
552+
"add": [Function],
553+
"create": [Function],
554+
"get": [Function],
555+
"getLastCreatedEntityKey": [Function],
556+
"mergeData": [Function],
557+
"replaceData": [Function],
558+
},
559+
"blockMap": Immutable.OrderedMap {
560+
"a": Immutable.Record {
561+
"key": "a",
562+
"type": "unstyled",
563+
"text": "",
564+
"characterList": Immutable.List [],
565+
"depth": 0,
566+
"data": Immutable.Map {},
567+
},
568+
},
569+
"selectionBefore": Immutable.Record {
570+
"anchorKey": "a",
571+
"anchorOffset": 0,
572+
"focusKey": "a",
573+
"focusOffset": 0,
574+
"isBackward": false,
575+
"hasFocus": false,
576+
},
577+
"selectionAfter": Immutable.Record {
578+
"anchorKey": "a",
579+
"anchorOffset": 0,
580+
"focusKey": "a",
581+
"focusOffset": 0,
582+
"isBackward": false,
583+
"hasFocus": false,
584+
},
585+
},
586+
"decorator": null,
587+
"directionMap": Immutable.OrderedMap {
588+
"a": "LTR",
589+
},
590+
"forceSelection": false,
591+
"inCompositionMode": false,
592+
"inlineStyleOverride": null,
593+
"lastChangeType": null,
594+
"nativelyRenderedContent": null,
595+
"redoStack": Immutable.Stack [],
596+
"selection": Immutable.Record {
597+
"anchorKey": "a",
598+
"anchorOffset": 0,
599+
"focusKey": "a",
600+
"focusOffset": 0,
601+
"isBackward": false,
602+
"hasFocus": false,
603+
},
604+
"treeMap": Immutable.OrderedMap {
605+
"a": Immutable.List [
606+
Immutable.Record {
607+
"start": 0,
608+
"end": 0,
609+
"decoratorKey": null,
610+
"leaves": Immutable.List [
611+
Immutable.Record {
612+
"start": 0,
613+
"end": 0,
614+
},
615+
],
616+
},
617+
],
618+
},
619+
"undoStack": Immutable.Stack [],
620+
},
621+
}
622+
}
623+
handleBeforeInput={[Function]}
624+
handleKeyCommand={[Function]}
625+
handlePastedText={[Function]}
626+
handleReturn={[Function]}
627+
onBlur={[Function]}
628+
onChange={[Function]}
629+
onDownArrow={[Function]}
630+
onFocus={[Function]}
631+
onTab={[Function]}
632+
onUpArrow={[Function]}
633+
plugins={
634+
Array [
635+
Object {
636+
"keyBindingFn": [Function],
637+
},
638+
]
639+
}
640+
readOnly={false}
641+
spellCheck={false}
642+
stripPastedStyles={true}
643+
textAlignment={null}
644+
textDirectionality={null}
645+
/>
646+
<div
647+
data-draftail-tooltip-parent={true}
648+
/>
437649
<Memo(Styles)
438-
max={1}
650+
blockKey="a"
651+
blockTypes={Array []}
652+
placeholder={null}
439653
/>
440654
</div>
441655
`;

0 commit comments

Comments
 (0)