Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render empty blocks #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sample/__tests__/components/DraftJsText.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,16 @@ it('renders text-align: center', () => {
/>).toJSON();
expect(tree).toMatchSnapshot();
});

it('renders empty blocks', () => {
const text = '';
const tree = renderer.create(<DraftJsText
type="paragraph"
text={text}
inlineStyles={[]}
entityRanges={[]}
entityMap={{}}
renderEmptyBlocks
/>).toJSON();
expect(tree).toMatchSnapshot();
});
19 changes: 19 additions & 0 deletions sample/__tests__/components/__snapshots__/DraftJsText.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ exports[`renders correctly with a text 1`] = `
</Text>
`;

exports[`renders empty blocks 1`] = `
<Text
style={
Array [
Object {
"fontSize": 14,
"fontWeight": "normal",
},
Object {
"textAlign": undefined,
},
undefined,
]
}
>

</Text>
`;

exports[`renders null without a text 1`] = `null`;

exports[`renders text-align: center 1`] = `
Expand Down
4 changes: 2 additions & 2 deletions src/components/DraftJsText.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import defaultStyles from './defaultStyles';
import type { DraftJsTextPropsType } from './types';

const DraftJsText = (props: DraftJsTextPropsType): any => {
const { text } = props;
const { text, renderEmptyBlocks } = props;
let textElements = text;

if (textElements) {
if (textElements || renderEmptyBlocks) {
textElements = loadAttributes({
text: props.text,
customStyles: props.customStyles,
Expand Down
4 changes: 4 additions & 0 deletions src/components/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type BlockQuotePropsType = {
entityRanges: Array<Object>,
entityMap: ?Object,
textProps: ?Object,
renderEmptyBlocks: boolean,
};

export type DraftJsTextPropsType = {
Expand All @@ -27,6 +28,7 @@ export type DraftJsTextPropsType = {
entityMap: ?Object,
navigate?: Function,
textProps: ?Object,
renderEmptyBlocks: boolean,
};

export type OrderedListItemPropsType = {
Expand All @@ -42,6 +44,7 @@ export type OrderedListItemPropsType = {
depth: number,
defaultMarginLeft: number,
textProps: ?Object,
renderEmptyBlocks: boolean,
};

export type UnorderedListItemPropsType = {
Expand All @@ -55,6 +58,7 @@ export type UnorderedListItemPropsType = {
depth: number,
defaultMarginLeft: number,
textProps: ?Object,
renderEmptyBlocks: boolean,
};

export type TextStyledPropsType = {
Expand Down
6 changes: 6 additions & 0 deletions src/getBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ParamsType = {
blocks: ?Array<*>,
entityMap: Object,
},
renderEmptyBlocks: boolean,
customStyles: Object,
atomicHandler: Function,
navigate?: Function,
Expand All @@ -36,6 +37,7 @@ export const ViewAfterList = (props: Object): React$Element<*> => (
const getBlocks = (params: ParamsType): ?Array<React$Element<*>> => {
const {
contentState,
renderEmptyBlocks,
customStyles,
navigate,
orderedListSeparator,
Expand Down Expand Up @@ -123,6 +125,7 @@ const getBlocks = (params: ParamsType): ?Array<React$Element<*>> => {
{viewBefore}
<DraftJsText
{...itemData}
renderEmptyBlocks={renderEmptyBlocks}
entityMap={contentState.entityMap}
customStyles={customStyles}
navigate={navigate}
Expand Down Expand Up @@ -160,6 +163,7 @@ const getBlocks = (params: ParamsType): ?Array<React$Element<*>> => {
customStyles={customStyles}
navigate={navigate}
textProps={textProps}
renderEmptyBlocks={renderEmptyBlocks}
/>
</View>
);
Expand All @@ -178,6 +182,7 @@ const getBlocks = (params: ParamsType): ?Array<React$Element<*>> => {
navigate={navigate}
defaultMarginLeft={depthMargin}
textProps={textProps}
renderEmptyBlocks={renderEmptyBlocks}
/>
</View>
);
Expand Down Expand Up @@ -217,6 +222,7 @@ const getBlocks = (params: ParamsType): ?Array<React$Element<*>> => {
navigate={navigate}
defaultMarginLeft={depthMargin}
textProps={textProps}
renderEmptyBlocks={renderEmptyBlocks}
/>
</View>
);
Expand Down