-
Notifications
You must be signed in to change notification settings - Fork 11
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
address two rich text editor bugs #210
Conversation
Southclaws
commented
Oct 12, 2024
•
edited
Loading
edited
- file upload input id non-unique so inserts into the wrong editor instance
- menu positioning broken
…ges being uploaded to the wrong editor instance
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces updates to the Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
web/src/components/content/ContentComposer/useContentComposer.ts (3)
9-9
: LGTM, but consider removing unused import.The addition of
useId
is appropriate for the newuniqueID
functionality. However,useMemo
is imported but not used in the visible changes.Consider removing the
useMemo
import if it's not needed, or comment on its intended use if it will be used in future changes.
71-71
: LGTM: Good use ofdata-editor-id
attribute.The addition of the
data-editor-id
attribute with theuniqueID
value is a good way to uniquely identify each editor instance. This will be helpful for targeting specific editor instances in JavaScript or CSS.For consistency with React naming conventions, consider using camelCase for the data attribute name:
data-editorId
.
198-198
: LGTM: ExposinguniqueID
in the return object.Adding
uniqueID
to the returned object is a good way to make this value available to consumers of the hook. This can be useful for components that need to reference the specific editor instance.Consider adding a comment or updating the function's JSDoc to document this new return value, explaining its purpose and potential uses.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- web/src/components/content/ContentComposer/ContentComposer.tsx (3 hunks)
- web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx (1 hunks)
- web/src/components/content/ContentComposer/useContentComposer.ts (3 hunks)
🧰 Additional context used
🔇 Additional comments (7)
web/src/components/content/ContentComposer/ContentComposer.tsx (5)
35-36
: LGTM: Addition ofuniqueID
to destructured propertiesThe inclusion of
uniqueID
in the destructured properties fromuseContentComposer
is a good addition. This will allow for unique identification of multipleContentComposer
instances, improving the component's flexibility and reusability.
40-40
: LGTM: Unique ID for LStack componentThe addition of
uniqueID
to theid
attribute of theLStack
component is a good practice. It ensures that each instance of theContentComposer
has a unique identifier for its container, which can be useful for styling, scripting, or accessibility purposes.
Line range hint
200-210
: LGTM: Unique IDs for file input and labelThe addition of
uniqueID
to both thehtmlFor
attribute of the label and theid
attribute of the file input is a good practice. This ensures that:
- Each instance of the
ContentComposer
has a unique file input.- The label is correctly associated with its corresponding input, maintaining accessibility.
These changes improve the component's ability to handle multiple instances without ID conflicts.
Line range hint
218-224
: LGTM: Unique ID for EditorContent componentThe addition of
uniqueID
to theid
attribute of theEditorContent
component is a good practice. It ensures that each instance of theContentComposer
has a unique identifier for its editor content, which can be beneficial for:
- Styling specific editor instances
- Scripting or event handling tied to specific editors
- Improved debugging and error reporting
This change aligns well with the overall approach of using unique identifiers throughout the component.
Line range hint
35-224
: Overall changes look good, consider verifyinguniqueID
generationThe changes to incorporate
uniqueID
throughout theContentComposer
component are consistent and well-implemented. They improve the component's ability to handle multiple instances without ID conflicts, which is crucial for larger applications.To ensure the robustness of this implementation:
- Verify that the
uniqueID
is properly generated and passed down from the parent component or generated withinuseContentComposer
.- Consider adding a prop type check or default value for
uniqueID
to handle cases where it might not be provided.To verify the
uniqueID
generation and usage, you can run the following script:This script will help ensure that
uniqueID
is properly handled throughout the related components.web/src/components/content/ContentComposer/useContentComposer.ts (2)
64-66
: LGTM: Good use ofuseId()
for unique identification.The addition of
uniqueID
usinguseId()
is a good practice for generating stable, unique identifiers. The comment clearly explains its purpose for the menu's file upload input ID.
Line range hint
1-258
: Overall assessment: Good improvements for multi-instance support.The changes in this file enhance the
useContentComposer
hook by adding unique identification for each editor instance. This is a valuable improvement for scenarios where multiple editors might be used on the same page. The implementation is clean and follows React best practices.Key points:
- Good use of
useId()
for generating stable, unique identifiers.- Proper application of the unique ID to the editor's attributes.
- Exposing the
uniqueID
in the hook's return object for flexibility.These changes will facilitate better management and targeting of individual editor instances, improving the overall functionality and maintainability of the component.
const offsetY = caretY + 16; | ||
const offsetX = containerLeft; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider aligning the floating menu horizontally with the caret position
Currently, offsetX
is set to containerLeft
, which positions the floating menu at the left edge of the editor. This may result in the menu appearing far from the caret when it's located towards the right side of the editor, potentially leading to a less intuitive user experience.
To improve usability, consider aligning the menu horizontally with the caret's position by using caretX
instead of containerLeft
.
Apply the following changes:
const { bottom: caretY } = posToDOMRect(view, from, to);
+const { left: caretX } = posToDOMRect(view, from, to);
const offsetY = caretY + 16;
-const offsetX = containerLeft;
+const offsetX = caretX;
// NOTE: Left is -1px for optical alignment due to the border radius.
this.element.setAttribute(
"style",
- `top: ${offsetY}px; left: ${offsetX - 1}px;`,
+ `top: ${offsetY}px; left: ${offsetX - 1}px;`,
);
Also applies to: 121-124
2bf0eed
to
6425b52
Compare