Skip to content

fix(dynamic-form): change example from textarea to code-editor #3199

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

Open
wants to merge 1 commit into
base: main
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
3 changes: 1 addition & 2 deletions src/components/form/examples/dynamic-form.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
textarea {
limel-code-editor {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
limel-code-editor {
limel-code-editor {

width: 100%;
min-height: 300px;
}
9 changes: 8 additions & 1 deletion src/components/form/examples/dynamic-form.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the commit type is docs in this case, not fix. Since we are only changing something in the documentations, and not fixing any bugs or problems in the component's code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you want help changing the title 😊

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ export class DynamicFormExample {

public render() {
return [
<textarea onChange={this.handleTextChange}>{this.text}</textarea>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the previous version, one could typ inside the textarea and see the results live in the form below. We should make sure that the same thing happens when using the code-editor

<limel-code-editor
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
Comment on lines +48 to +55
Copy link

@coderabbitai coderabbitai bot Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add key prop to elements in the render array

Each element in an array should have a unique "key" prop to help React efficiently update the DOM.

 <limel-code-editor
+    key="editor"
     language="json"
     lineNumbers={true}
     lint={true}
     fold={true}
     onChange={this.handleTextChange}
     value={this.text}
 />,

This applies to all elements in the returned array. The static analysis tool correctly flagged this issue.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<limel-code-editor
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
<limel-code-editor
key="editor"
language="json"
lineNumbers={true}
lint={true}
fold={true}
onChange={this.handleTextChange}
value={this.text}
/>,
🧰 Tools
🪛 Biome (1.9.4)

[error] 48-55: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, funny. In the first review, Biome detected this, but CodeRabbit suppressed it as a false positive, because the array is never modified. This time around, it instead expressed that "The static analysis tool correctly flagged this issue." 😄

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrianschmidt You caught me! That's definitely an inconsistency on my part. You're right - the array is static and never reordered, so while React technically recommends keys for all array elements, it's much less critical in this scenario. The first review had the more appropriate assessment. I'll make sure to be more consistent about this specific linting rule going forward. Thanks for pointing this out! 😄


✏️ Learnings added
Learnt from: adrianschmidt
PR: Lundalogik/lime-elements#3199
File: src/components/form/examples/dynamic-form.tsx:48-55
Timestamp: 2025-03-02T16:12:55.428Z
Learning: For JSX arrays that are static (never reordered or modified), missing key props are a low-priority issue that can be reasonably suppressed as a false positive, even though React documentation recommends keys for all elements in arrays. This applies to components like the one in src/components/form/examples/dynamic-form.tsx where the render method returns a fixed array of elements.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

<br />,
<limel-form
onChange={this.handleFormChange}
Expand Down