-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[PE-265] fix: adding link to editor via floating toolbar #6517
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
Conversation
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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: 0
🧹 Nitpick comments (2)
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (2)
23-35: Enhance URL validation and protocol handling.While the current implementation works, consider these improvements:
- Support for HTTPS protocol by default instead of HTTP
- Handle more URL formats (e.g., FTP, custom protocols)
- Provide more specific error messages based on validation failure reason
Consider this enhanced implementation:
const handleLinkSubmit = useCallback(() => { const input = inputRef.current; if (!input) return; let url = input.value; if (!url) return; - if (!url.startsWith("http")) url = `http://${url}`; + // Support common protocols or default to HTTPS + const commonProtocols = ['http:', 'https:', 'ftp:', 'mailto:']; + const hasProtocol = commonProtocols.some(protocol => url.startsWith(protocol)); + if (!hasProtocol) url = `https://${url}`; + if (isValidHttpUrl(url)) { setLinkEditor(editor, url); setIsOpen(false); setError(false); } else { setError(true); + // Set more specific error message based on validation failure + const errorMessage = url.includes('://') + ? 'Invalid URL format' + : 'Please enter a valid URL'; + setErrorMessage(errorMessage); } }, [editor, inputRef, setIsOpen]);
58-109: Enhance accessibility for the link selector.While the UI implementation looks good, consider these accessibility improvements:
- Add ARIA labels for error messages
- Include role attributes for interactive elements
- Add keyboard navigation between buttons
Apply these accessibility enhancements:
<div className={cn("flex rounded border border-custom-border-300 transition-colors", { "border-red-500": error, })} + role="group" + aria-label="Link editor" > <input ref={inputRef} type="url" placeholder="Enter or paste a link" onClick={(e) => e.stopPropagation()} className="flex-1 border-r border-custom-border-300 bg-custom-background-100 py-2 px-1.5 text-xs outline-none placeholder:text-custom-text-400 rounded" defaultValue={editor.getAttributes("link").href || ""} + aria-invalid={error} + aria-describedby={error ? "link-error-message" : undefined} onKeyDown={(e) => { setError(false); if (e.key === "Enter") { e.preventDefault(); handleLinkSubmit(); + } else if (e.key === "Tab") { + // Prevent focus trap + e.stopPropagation(); } }} onFocus={() => setError(false)} autoFocus /> {/* ... buttons ... */} </div> {error && ( <p className="text-xs text-red-500 my-1 px-2 pointer-events-none animate-in fade-in slide-in-from-top-0" + id="link-error-message" + role="alert" > Please enter a valid URL </p> )}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (python)
🔇 Additional comments (2)
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (2)
2-2: LGTM! Icon import updated consistently.The Trash2 icon import aligns with its usage in the component.
19-19: LGTM! Error state added for validation feedback.The error state addition improves user feedback for invalid URLs.
Description
This PR includes-
Type of Change
Summary by CodeRabbit
New Features
Bug Fixes