Skip to content

Commit 3883fb7

Browse files
committed
feat(editor): enhance rich editor toolbar behavior
- Implement sticky detection for the rich editor toolbar. - Adjust CSS to hide shadow when the toolbar is not sticky. - Update component structure to support new sticky detection logic. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 6fa2a38 commit 3883fb7

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/components/editor/write-editor/WriteEditorBase.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ export const WriteEditorBase = defineComponent({
7171
const scrollContainerRef = ref<HTMLElement>()
7272
const { general, destory } = useEditorConfig()
7373
const titleInputRef = ref<{ focus: () => void }>()
74+
const stickyDetectorRef = ref<HTMLElement>()
75+
const isToolbarStuck = ref(false)
76+
77+
onMounted(() => {
78+
const el = stickyDetectorRef.value
79+
if (!el) return
80+
const scrollRoot = el.closest('.n-scrollbar-container') as Element | null
81+
const observer = new IntersectionObserver(
82+
([entry]) => {
83+
isToolbarStuck.value = !entry.isIntersecting
84+
},
85+
{ root: scrollRoot, threshold: 0 },
86+
)
87+
observer.observe(el)
88+
onUnmounted(() => observer.disconnect())
89+
})
7490

7591
onUnmounted(() => {
7692
destory()
@@ -149,6 +165,7 @@ export const WriteEditorBase = defineComponent({
149165
class={[
150166
'write-editor-wrapper min-h-[100dvh]',
151167
isRichMode.value && 'rich-editor-mode',
168+
isToolbarStuck.value && 'toolbar-stuck',
152169
]}
153170
>
154171
<div ref={scrollContainerRef} class="write-editor-scroll-container">
@@ -225,6 +242,8 @@ export const WriteEditorBase = defineComponent({
225242
)}
226243
</div>
227244

245+
<div ref={stickyDetectorRef} class="h-0 w-full" aria-hidden />
246+
228247
<div
229248
class="write-editor-content"
230249
onClick={() => {

src/components/editor/write-editor/index.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
display: flex;
55
flex-direction: column;
66
height: 100%;
7-
overflow: clip;
87
}
98

109
.write-editor-scroll-container {
1110
position: relative;
1211
flex: 1;
1312
display: flex;
1413
flex-direction: column;
15-
overflow-y: auto;
1614
}
1715

1816
.write-editor-header {
@@ -124,3 +122,12 @@
124122
.write-editor-wrapper.rich-editor-mode .write-editor-content > div {
125123
height: auto;
126124
}
125+
126+
/* Rich editor toolbar: hide shadow when not sticky */
127+
.write-editor-wrapper.rich-editor-mode [role='toolbar'] {
128+
box-shadow: none;
129+
}
130+
131+
.write-editor-wrapper.rich-editor-mode.toolbar-stuck [role='toolbar'] {
132+
box-shadow: var(--rc-shadow-top-bar);
133+
}

0 commit comments

Comments
 (0)