From a5448a00530794475ea39a1b2974bb743a7a874b Mon Sep 17 00:00:00 2001 From: sudhir Date: Fri, 24 Apr 2026 10:43:38 +0530 Subject: [PATCH] Make material categories horizontally scrollable --- .../ui/controls/material-picker.tsx | 76 +++++++++++++------ 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/packages/editor/src/components/ui/controls/material-picker.tsx b/packages/editor/src/components/ui/controls/material-picker.tsx index dbe0a6e3..ce743482 100755 --- a/packages/editor/src/components/ui/controls/material-picker.tsx +++ b/packages/editor/src/components/ui/controls/material-picker.tsx @@ -31,6 +31,7 @@ export function MaterialPicker({ const [showCustom, setShowCustom] = useState(!!value?.properties) const [selectedCategory, setSelectedCategory] = useState(MATERIAL_CATEGORIES[0]) const catalogScrollRef = useRef(null) + const categoryScrollRef = useRef(null) const catalogItems = selectedCategory === 'other' ? getMaterialsForCategory('other') @@ -87,6 +88,27 @@ export function MaterialPicker({ } }, [catalogItems.length, onChange, showCustom]) + useEffect(() => { + const container = categoryScrollRef.current + if (!container) return + + const handleWheel = (event: WheelEvent) => { + const deltaX = event.deltaX + const deltaY = event.deltaY + const nextScrollLeft = container.scrollLeft + deltaX + deltaY + + if (nextScrollLeft === container.scrollLeft) return + + event.preventDefault() + container.scrollLeft = nextScrollLeft + } + + container.addEventListener('wheel', handleWheel, { passive: false }) + return () => { + container.removeEventListener('wheel', handleWheel) + } + }, []) + const handleCustomOpen = () => { if (disabled) return setShowCustom(true) @@ -110,30 +132,36 @@ export function MaterialPicker({ return (
{(catalogItems.length > 0 || onChange) && ( -
-
- {MATERIAL_CATEGORIES.map((category) => ( - - ))} +
+
+
+ {MATERIAL_CATEGORIES.map((category) => ( + + ))} +