Skip to content

Commit f8ed345

Browse files
committed
fix: editor
1 parent 78ce9e3 commit f8ed345

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/components/MarkdownEditor.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ export function MarkdownEditor({
1919
rows = 6
2020
}: MarkdownEditorProps) {
2121
const [showPreview, setShowPreview] = useState(false);
22+
const [isMobile, setIsMobile] = useState(false);
2223
const textareaRef = useRef<HTMLTextAreaElement>(null);
2324
const { t } = useTranslation();
2425

26+
useEffect(() => {
27+
const checkMobile = () => {
28+
setIsMobile(window.innerWidth < 768);
29+
};
30+
31+
checkMobile();
32+
window.addEventListener('resize', checkMobile);
33+
return () => window.removeEventListener('resize', checkMobile);
34+
}, []);
35+
2536
const insertText = (before: string, after: string = '', placeholder: string = '') => {
2637
const textarea = textareaRef.current;
2738
if (!textarea) return;
@@ -112,7 +123,7 @@ export function MarkdownEditor({
112123
};
113124

114125
return (
115-
<div className={`border border-gray-300 dark:border-gray-600 rounded-md ${className}`}>
126+
<div className={`border border-gray-300 dark:border-gray-600 rounded-md ${isMobile ? 'markdown-editor-mobile' : ''} ${className}`}>
116127
{/* Toolbar */}
117128
<div className="flex items-center gap-1 p-2 border-b border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 rounded-t-md">
118129
{toolbarButtons.map((button, index) => (
@@ -161,7 +172,7 @@ export function MarkdownEditor({
161172
onKeyDown={handleKeyDown}
162173
placeholder={placeholder}
163174
rows={rows}
164-
className="w-full p-4 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 font-mono text-sm resize-y focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent rounded-b-md"
175+
className={`w-full p-4 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 font-mono text-sm resize-y focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent rounded-b-md ${isMobile ? 'max-w-full box-border' : ''}`}
165176
/>
166177
)}
167178
</div>

src/index.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,43 @@
7676
margin: auto;
7777
}
7878

79+
/* MarkdownEditor mobile fixes */
80+
.markdown-editor-mobile {
81+
max-width: 100%;
82+
box-sizing: border-box;
83+
}
84+
85+
.markdown-editor-mobile textarea {
86+
max-width: 100%;
87+
box-sizing: border-box;
88+
word-wrap: break-word;
89+
overflow-wrap: break-word;
90+
}
91+
92+
@media screen and (max-width: 480px) {
93+
.modal-dialog {
94+
max-width: calc(100vw - 2rem); /* Account for padding */
95+
}
96+
97+
.markdown-editor-mobile {
98+
margin-left: -0.5rem;
99+
margin-right: -0.5rem;
100+
width: calc(100% + 1rem);
101+
}
102+
103+
.markdown-editor-mobile .p-4 {
104+
padding: 0.75rem;
105+
}
106+
107+
.markdown-editor-mobile .p-2 {
108+
padding: 0.5rem;
109+
}
110+
111+
.markdown-editor-mobile .p-1\\.5 {
112+
padding: 0.375rem;
113+
}
114+
}
115+
79116
@media screen and (min-width: 768px) {
80117
.modal-content {
81118
min-height: auto;

0 commit comments

Comments
 (0)