Skip to content

Commit 4191bca

Browse files
authored
Use ResizeObserver to conditionally render SchemaTabs arrows (#322)
1 parent 964b405 commit 4191bca

File tree

1 file changed

+14
-5
lines changed
  • packages/docusaurus-theme-openapi-docs/src/theme/SchemaTabs

1 file changed

+14
-5
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/SchemaTabs/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,21 @@ function SchemaTabsComponent(props) {
147147
const [showTabArrows, setShowTabArrows] = useState(false);
148148

149149
useEffect(() => {
150-
const tabOffsetWidth = tabItemListContainerRef.current.offsetWidth;
151-
const tabScrollWidth = tabItemListContainerRef.current.scrollWidth;
150+
const resizeObserver = new ResizeObserver((entries) => {
151+
for (let entry of entries) {
152+
if (entry.target.offsetWidth < entry.target.scrollWidth) {
153+
setShowTabArrows(true);
154+
} else {
155+
setShowTabArrows(false);
156+
}
157+
}
158+
});
152159

153-
if (tabOffsetWidth < tabScrollWidth) {
154-
setShowTabArrows(true);
155-
}
160+
resizeObserver.observe(tabItemListContainerRef.current);
161+
162+
return () => {
163+
resizeObserver.disconnect();
164+
};
156165
}, []);
157166

158167
const handleRightClick = () => {

0 commit comments

Comments
 (0)