Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] fixed hook issue in segmented-control #2608

Merged
merged 1 commit into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/mantine-core/src/SegmentedControl/SegmentedControl.story.tsx
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import { Button } from '../Button';
import { SegmentedControl } from './SegmentedControl';

export default { title: 'SegmentedControl' };
Expand All @@ -18,6 +19,18 @@ export function EmptyData() {
return <SegmentedControl data={[]} />;
}

export function ToggleEmptyData() {
const [emptyData, setEmptyData] = useState(true);

return (
<>
<Button onClick={() => setEmptyData((e) => !e)}>Toggle Data</Button>
<br />
<SegmentedControl data={emptyData ? [] : data} />
</>
);
}

export function EmptyStringValue() {
const [value, onChange] = useState('');
return (
Expand Down
4 changes: 3 additions & 1 deletion src/mantine-core/src/SegmentedControl/SegmentedControl.tsx
Expand Up @@ -206,12 +206,14 @@ export const SegmentedControl = forwardRef<HTMLDivElement, SegmentedControlProps
</div>
));

const mergedRef = useMergedRef(observerRef, ref);

if (data.length === 0) {
return null;
}

return (
<Box className={cx(classes.root, className)} ref={useMergedRef(observerRef, ref)} {...others}>
<Box className={cx(classes.root, className)} ref={mergedRef} {...others}>
{typeof _value === 'string' && shouldAnimate && (
<Box
component="span"
Expand Down