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][select] Fix screen-reader CSS to avoid body scrollbar #40599

Merged
merged 1 commit into from
Jan 16, 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
11 changes: 5 additions & 6 deletions packages/mui-base/src/useSelect/useSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ describe('useSelect', () => {
required: true,
value: 'b',
style: {
clip: 'rect(1px, 1px, 1px, 1px)',
clipPath: 'inset(50%)',
border: 0,
clip: 'rect(0 0 0 0)',
height: '1px',
width: '1px',
margin: '-1px',
margin: -1,
overflow: 'hidden',
padding: 0,
position: 'absolute',
left: '50%',
bottom: 0,
whiteSpace: 'nowrap',
width: '1px',
},
});
});
Expand Down
15 changes: 1 addition & 14 deletions packages/mui-base/src/useSelect/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
unstable_useForkRef as useForkRef,
unstable_useId as useId,
unstable_useEnhancedEffect as useEnhancedEffect,
visuallyHidden as visuallyHiddenStyle,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-topic

One day, it would be great to move this to its own folder

Suggested change
visuallyHidden as visuallyHiddenStyle,
import { visuallyHidden } from '@mui/utils/visuallyHidden',

per #35840

} from '@mui/utils';
import { useButton } from '../useButton';
import {
Expand All @@ -29,20 +30,6 @@ import { selectReducer } from './selectReducer';
import { combineHooksSlotProps } from '../utils/combineHooksSlotProps';
import { MuiCancellableEvent } from '../utils/MuiCancellableEvent';

// visually hidden style based on https://webaim.org/techniques/css/invisiblecontent/
const visuallyHiddenStyle: React.CSSProperties = {
clip: 'rect(1px, 1px, 1px, 1px)',
clipPath: 'inset(50%)',
height: '1px',
width: '1px',
margin: '-1px',
overflow: 'hidden',
padding: 0,
position: 'absolute',
left: '50%',
bottom: 0, // to display the native browser validation error at the bottom of the Select.
};

function defaultFormValueProvider<OptionValue>(
selectedOption: SelectOption<OptionValue> | SelectOption<OptionValue>[] | null,
) {
Expand Down
Loading