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

[base-ui][docs] Update the Accessibility page demos design #40995

Merged
merged 3 commits into from
Feb 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const Select = React.forwardRef(function CustomSelect(props, ref) {
return {
...resolvedSlotProps,
className: clsx(
`${isDarkMode ? 'dark' : ''} z-10x`,
`${isDarkMode ? 'dark' : ''} z-10`,
resolvedSlotProps?.className,
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const Select = React.forwardRef(function CustomSelect<
return {
...resolvedSlotProps,
className: clsx(
`${isDarkMode ? 'dark' : ''} z-10x`,
`${isDarkMode ? 'dark' : ''} z-10`,
resolvedSlotProps?.className,
),
};
Expand Down
51 changes: 31 additions & 20 deletions docs/data/base/getting-started/accessibility/FocusRing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,70 @@ const Slider = styled(BaseSlider)(
height: 6px;
width: 100%;
padding: 16px 0;
display: inline-block;
display: inline-flex;
align-items: center;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;

&:hover {
opacity: 1;
}

& .${sliderClasses.rail} {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 2px;
border-radius: 6px;
background-color: currentColor;
opacity: 0.4;
opacity: 0.3;
}

& .${sliderClasses.track} {
display: block;
position: absolute;
height: 4px;
border-radius: 2px;
border-radius: 6px;
background-color: currentColor;
}

& .${sliderClasses.thumb} {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
width: 16px;
height: 16px;
margin-left: -6px;
margin-top: -6px;
width: 20px;
height: 20px;
box-sizing: border-box;
border-radius: 50%;
outline: 0;
border: 3px solid currentColor;
background-color: #fff;
background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]};
transition-property: box-shadow, transform;
transition-timing-function: ease;
transition-duration: 120ms;
transform-origin: center;

&:hover {
box-shadow: 0 0 0 6px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[300],
0.3,
)};
}

:hover,
&.${sliderClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[400] : blue[300],
0.15,
box-shadow: 0 0 0 8px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[400],
0.5,
)};
outline: none;
}

&.${sliderClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[300],
0.3,
box-shadow: 0 0 0 8px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[400],
0.5,
)};
outline: none;
transform: scale(1.2);
}
}
`,
Expand Down
51 changes: 31 additions & 20 deletions docs/data/base/getting-started/accessibility/FocusRing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,70 @@ const Slider = styled(BaseSlider)(
height: 6px;
width: 100%;
padding: 16px 0;
display: inline-block;
display: inline-flex;
align-items: center;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;

&:hover {
opacity: 1;
}

& .${sliderClasses.rail} {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 2px;
border-radius: 6px;
background-color: currentColor;
opacity: 0.4;
opacity: 0.3;
}

& .${sliderClasses.track} {
display: block;
position: absolute;
height: 4px;
border-radius: 2px;
border-radius: 6px;
background-color: currentColor;
}

& .${sliderClasses.thumb} {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
width: 16px;
height: 16px;
margin-left: -6px;
margin-top: -6px;
width: 20px;
height: 20px;
box-sizing: border-box;
border-radius: 50%;
outline: 0;
border: 3px solid currentColor;
background-color: #fff;
background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]};
transition-property: box-shadow, transform;
transition-timing-function: ease;
transition-duration: 120ms;
transform-origin: center;

&:hover {
box-shadow: 0 0 0 6px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[300],
0.3,
)};
}

:hover,
&.${sliderClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[400] : blue[300],
0.15,
box-shadow: 0 0 0 8px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[400],
0.5,
)};
outline: none;
}

&.${sliderClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[300],
0.3,
box-shadow: 0 0 0 8px ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[400],
0.5,
)};
outline: none;
transform: scale(1.2);
}
}
`,
Expand Down
83 changes: 50 additions & 33 deletions docs/data/base/getting-started/accessibility/KeyboardNavigation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Select as BaseSelect, selectClasses } from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Dropdown } from '@mui/base/Dropdown';
import { Menu } from '@mui/base/Menu';
import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton';
import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem';
import { styled } from '@mui/system';
import { styled, alpha } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';

export default function KeyboardNavigation() {
return (
Expand All @@ -23,7 +25,7 @@ export default function KeyboardNavigation() {
</Select>

<Dropdown>
<MenuButton>Edit</MenuButton>
<MenuButton>Open menu</MenuButton>
<Menu slots={{ listbox: Listbox }}>
<MenuItem>Cut</MenuItem>
<MenuItem>Copy</MenuItem>
Expand All @@ -36,7 +38,7 @@ export default function KeyboardNavigation() {

const Select = React.forwardRef(function Select(props, ref) {
const slots = {
root: Button,
root: SelectButton,
listbox: Listbox,
popup: Popup,
...props.slots,
Expand All @@ -45,6 +47,21 @@ const Select = React.forwardRef(function Select(props, ref) {
return <BaseSelect {...props} ref={ref} slots={slots} />;
});

const SelectButton = React.forwardRef(function SelectButton(props, ref) {
const { ownerState, ...other } = props;
return (
<StyledSelectButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledSelectButton>
);
});

SelectButton.propTypes = {
children: PropTypes.node,
ownerState: PropTypes.object.isRequired,
};

const blue = {
50: '#F0F7FF',
100: '#DAECFF',
Expand All @@ -69,8 +86,9 @@ const grey = {
900: '#24292f',
};

const Button = styled('button')(
const StyledSelectButton = styled('button')(
({ theme }) => `
position: relative;
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
Expand All @@ -79,36 +97,34 @@ const Button = styled('button')(
border-radius: 8px;
text-align: left;
line-height: 1.5;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? alpha(grey[900], 0.4) : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[900] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
box-shadow: 0px 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.2)' : 'rgba(0,0,0, 0.1)'
};

transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;

&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[300]};
}

&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}

&.${selectClasses.expanded} {
&::after {
content: '▴';
}
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}

&::after {
content: '▾';
float: right;
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
Expand All @@ -120,14 +136,14 @@ const Listbox = styled('ul')(
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
min-width: 150px;
min-width: 200px;
border-radius: 12px;
overflow: auto;
outline: 0px;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
box-shadow: 0px 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
Expand All @@ -154,15 +170,15 @@ const Option = styled(BaseOption)(
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}

&:focus-visible {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}

&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}

&:focus-visible {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}

&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
Expand Down Expand Up @@ -212,18 +228,19 @@ const MenuButton = styled(BaseMenuButton)(
border-radius: 8px;
padding: 8px 16px;
line-height: 1.5;
background: transparent;
background: ${
theme.palette.mode === 'dark' ? alpha(grey[900], 0.5) : alpha(grey[50], 0.5)
};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
color: ${theme.palette.mode === 'dark' ? blue[300] : blue[500]};
cursor: pointer;
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[800]};

transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;

&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[100]};
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[300]};
}

&:focus-visible {
Expand All @@ -235,7 +252,7 @@ const MenuButton = styled(BaseMenuButton)(

const Container = styled('div')`
display: flex;
gap: 10px;
gap: 12px;
`;

const Popup = styled('div')`
Expand Down
Loading
Loading