feat(ui): add pending/update toast state and shared floating-menu positioning
Toast gains a pending/update lifecycle so async actions can show a single toast that transitions from in-progress to success/error, instead of firing a new one. Select's floating-menu placement logic is extracted into a shared helper so other dropdown-style components (MultiSelect) can reuse it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import { useState, useRef, useEffect, Children, isValidElement } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { computeFloatingMenuPosition } from '@/lib/floatingMenuPosition'
|
||||
|
||||
// Parse React <option> children into a flat [{value, label, disabled}] array
|
||||
function parseOptions(children) {
|
||||
@@ -46,7 +47,7 @@ export default function Select({
|
||||
...props
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [menuPos, setMenuPos] = useState({ top: 0, left: 0, width: 0 })
|
||||
const [menuPos, setMenuPos] = useState({ top: 0, left: 0, width: 0, maxHeight: 280 })
|
||||
const triggerRef = useRef(null)
|
||||
const menuRef = useRef(null)
|
||||
|
||||
@@ -105,8 +106,7 @@ export default function Select({
|
||||
function openMenu() {
|
||||
if (disabled) return
|
||||
if (triggerRef.current) {
|
||||
const r = triggerRef.current.getBoundingClientRect()
|
||||
setMenuPos({ top: r.bottom + 4, left: r.left, width: r.width })
|
||||
setMenuPos(computeFloatingMenuPosition(triggerRef.current.getBoundingClientRect()))
|
||||
}
|
||||
setOpen(true)
|
||||
}
|
||||
@@ -130,7 +130,7 @@ export default function Select({
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="select-menu"
|
||||
style={{ top: menuPos.top, left: menuPos.left, width: menuPos.width }}
|
||||
style={{ top: menuPos.top, bottom: menuPos.bottom, left: menuPos.left, width: menuPos.width, maxHeight: menuPos.maxHeight }}
|
||||
role="listbox"
|
||||
aria-label="Options"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user