Skip to content

Commit

Permalink
Web: SlideTabs, prevent click instead of using pointer-events (#44114)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa authored Jul 20, 2024
1 parent bea2d21 commit fc31399
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 11 additions & 0 deletions web/packages/design/src/SlideTabs/SlideTabs.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ export const LoadingTab = () => {
/>
);
};

export const DisabledTab = () => {
return (
<SlideTabs
tabs={['aws', 'automatically', 'manually']}
onChange={() => null}
activeIndex={1}
disabled={true}
/>
);
};
17 changes: 10 additions & 7 deletions web/packages/design/src/SlideTabs/SlideTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ export function SlideTabs({
<TabNav role="tablist" appearance={appearance} size={size}>
{tabs.map((tabName, tabIndex) => {
const selected = tabIndex === activeIndex;
let onClick;
if (!disabled && !isProcessing) {
onClick = (e: React.MouseEvent<HTMLLabelElement, MouseEvent>) => {
e.preventDefault();
onChange(tabIndex);
};
}
return (
<TabLabel
role="tab"
htmlFor={`${name}-${tabName}`}
onClick={e => {
e.preventDefault();
onChange(tabIndex);
}}
onClick={onClick}
itemCount={tabs.length}
key={`${tabName}-${tabIndex}`}
className={tabIndex === activeIndex && 'selected'}
Expand Down Expand Up @@ -123,14 +127,13 @@ const TabLabel = styled.label<{
processing?: boolean;
disabled?: boolean;
}>`
cursor: pointer;
cursor: ${p => (p.processing || p.disabled ? 'default' : 'pointer')};
display: flex;
justify-content: center;
padding: 10px;
width: ${props => 100 / props.itemCount}%;
z-index: 1; /* Ensures that the label is above the background slider. */
opacity: ${p => (p.processing ? 0.5 : 1)};
pointer-events: ${p => (p.processing || p.disabled ? 'none' : 'auto')};
opacity: ${p => (p.processing || p.disabled ? 0.5 : 1)};
`;

const TabInput = styled.input`
Expand Down

0 comments on commit fc31399

Please sign in to comment.