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

chore(rich-text-editor)!: Rename value to defaultValue #29

Merged
merged 2 commits into from
Sep 12, 2023
Merged
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
23 changes: 23 additions & 0 deletions .changeset/fluffy-camels-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@kaizen/rich-text-editor": major
---

Rename `value` prop to reflect uncontrolled form field

To conform to React naming convention for form control props.
Uncontrolled form fields take a `defaultValue` to indicate that
changes to this prop's value will not update the mounted component.
Rather, the component manages its current value as internal state,
and notifies subscribers via `onChange` when it changes.

Consumers will need to update their code to the new prop name. E.g. before:

```jsx
<RichTextEditor value={…}>
```

and after:

```jsx
<RichTextEditor defaultValue={…}>
```
10 changes: 9 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/packages/**/dist
/packages/**/dist
/draft-packages/**/*.js
/draft-packages/**/*.js.map
/draft-packages/**/*.d.ts
/packages/**/*.js
!/packages/**/*.config.js
!/packages/**/svgMock.js
/packages/**/*.js.map
/packages/**/*.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function InlineEditor(props: {
{ name: "bulletList", group: "list" },
{ name: "link", group: "link" },
]}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
/>
<Box mt={0.5} style={{ display: "flex", justifyContent: "end" }}>
Expand Down
12 changes: 6 additions & 6 deletions packages/rich-text-editor/docs/RichTextEditor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dummyContent from "./dummyContent.json"
import dummyMalformedContent from "./dummyMalformedContent.json"

type RTEStory = StoryFn<
Omit<RichTextEditorProps, "value" | "onChange" | "aria-labelledby">
Omit<RichTextEditorProps, "defaultValue" | "onChange" | "aria-labelledby">
>

export default {
Expand All @@ -32,7 +32,7 @@ export const Default: RTEStory = ({ labelText, ...args }) => {
return (
<RichTextEditor
labelText={labelText}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
{...args}
/>
Expand Down Expand Up @@ -60,7 +60,7 @@ export const WithData: RTEStory = ({ labelText, ...args }) => {
return (
<RichTextEditor
labelText={labelText}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
{...args}
/>
Expand Down Expand Up @@ -89,7 +89,7 @@ export const WithBadData: RTEStory = ({ labelText, ...args }) => {
return (
<RichTextEditor
labelText={labelText}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
{...args}
/>
Expand Down Expand Up @@ -121,14 +121,14 @@ export const WithDescriptionAndValidationMessage: RTEStory = ({
<>
<RichTextEditor
labelText={labelText}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
status="error"
{...args}
/>
<RichTextEditor
labelText={labelText}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
status="caution"
{...args}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TestBase: Story = {
return (
<RichTextEditor
labelText="Label"
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
rows={3}
controls={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ const getSelectionOfNode = (node: Node): void => {
}

const TestRTE = (
args: Omit<RichTextEditorProps, "value" | "onChange" | "aria-labelledby"> & {
rteMockData?: RichTextEditorProps["value"]
args: Omit<
RichTextEditorProps,
"defaultValue" | "onChange" | "aria-labelledby"
> & {
rteMockData?: RichTextEditorProps["defaultValue"]
}
): JSX.Element => {
const { rteMockData, ...rest } = args
Expand All @@ -34,7 +37,7 @@ const TestRTE = (
{ name: "orderedList", group: "list" },
{ name: "bulletList", group: "list" },
]}
value={rteData}
defaultValue={rteData}
onChange={handleOnChange}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import styles from "./RichTextEditor.module.scss"

export interface BaseRichTextEditorProps
extends OverrideClassName<
Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "content">
Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue">
> {
onChange: (content: ProseMirrorState.EditorState) => void
value: EditorContentArray
defaultValue: EditorContentArray
controls?: ToolbarItems[]
/**
* Sets a default min-height for the editable area in units of body paragraph line height, similar to the 'rows' attribute on <textarea>.
Expand Down Expand Up @@ -64,7 +64,7 @@ export type RichTextEditorProps = RTEWithLabelText | RTEWithLabelledBy
export const RichTextEditor = (props: RichTextEditorProps): JSX.Element => {
const {
onChange,
value,
defaultValue,
labelText,
"aria-labelledby": labelledBy,
classNameOverride,
Expand Down Expand Up @@ -93,7 +93,8 @@ export const RichTextEditor = (props: RichTextEditorProps): JSX.Element => {
type: "doc",
// we're converting empty arrays to the ProseMirror default "empty" state because when
// given an empty array ProseMirror returns undefined, breaking the type
content: value?.length > 0 ? value : [{ type: "paragraph" }],
content:
defaultValue?.length > 0 ? defaultValue : [{ type: "paragraph" }],
}),
schema,
plugins: getPlugins(controls, schema),
Expand Down