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

[system] Introduce visuallyHidden style utility #21413

Merged
merged 39 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c953f9e
init
mnajdova Jun 13, 2020
4e9c6b8
proptypes + prettier
mnajdova Jun 13, 2020
dfcc14d
docs:api
mnajdova Jun 13, 2020
3cec1e1
fixed test
mnajdova Jun 13, 2020
829b793
renamed examples names
mnajdova Jun 13, 2020
fcae609
Update packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js
mnajdova Jun 13, 2020
c7c7170
Update packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js
mnajdova Jun 13, 2020
4cccf65
Update packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js
mnajdova Jun 13, 2020
f8ab6bd
comments
mnajdova Jun 13, 2020
ce4cd15
Update docs/src/pages/components/visually-hidden/visually-hidden.md
mnajdova Jun 13, 2020
4348541
description
mnajdova Jun 13, 2020
070f2d9
Merge branch 'fat/visually-hidden' of https://github.com/mnajdova/mat…
mnajdova Jun 13, 2020
ac287b7
merge
mnajdova Jun 13, 2020
e095fe5
renamed className for visualHidden in Rating
mnajdova Jun 13, 2020
393c245
removed component, added styles util
mnajdova Jun 13, 2020
592b451
removed srOnly from Typography
mnajdova Jun 13, 2020
6abfaf3
polishing
mnajdova Jun 13, 2020
d57387c
better description
mnajdova Jun 13, 2020
7ef59e2
removed export
mnajdova Jun 13, 2020
299292b
prettier
mnajdova Jun 13, 2020
4c2256a
Update packages/material-ui-system/src/index.d.ts
mnajdova Jun 13, 2020
1d3d245
reverted translation pages
mnajdova Jun 13, 2020
6d084a5
removed component page
mnajdova Jun 13, 2020
d919b9b
removed styles as dependency
mnajdova Jun 14, 2020
e33085c
added cast
mnajdova Jun 14, 2020
236450b
ts formatted
mnajdova Jun 14, 2020
e50d107
ts fixes
mnajdova Jun 14, 2020
aa96cc6
Merge branch 'next' into fat/visually-hidden
mnajdova Jun 14, 2020
1ecd2e9
updated migration guide
mnajdova Jun 14, 2020
b0d1158
styled components
mnajdova Jun 14, 2020
54a1c6d
renamed page to screen readers
mnajdova Jun 14, 2020
ea9ba89
reverted styled components usage
mnajdova Jun 14, 2020
2fa6d93
added htmlFor and id
mnajdova Jun 14, 2020
085286f
added comment for fixing ts issue
mnajdova Jun 14, 2020
1cd1658
simplified example
mnajdova Jun 14, 2020
9de377c
Used Link component
mnajdova Jun 14, 2020
ddfbf4e
typo
mnajdova Jun 14, 2020
0dd8163
prettier
mnajdova Jun 14, 2020
8807efc
Update docs/src/pages/guides/migration-v4/migration-v4.md
oliviertassinari Jun 14, 2020
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
2 changes: 1 addition & 1 deletion docs/pages/api-docs/rating.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Any other props supplied will be provided to the root element (native element).
| <span class="prop-name">readOnly</span> | <span class="prop-name">.MuiRating-readOnly</span> | Styles applied to the root element if `readOnly={true}`.
| <span class="prop-name">disabled</span> | <span class="prop-name">.Mui-disabled</span> | Pseudo-class applied to the root element if `disabled={true}`.
| <span class="prop-name">focusVisible</span> | <span class="prop-name">.Mui-focusVisible</span> | Pseudo-class applied to the root element if keyboard focused.
| <span class="prop-name">visuallyhidden</span> | <span class="prop-name">.MuiRating-visuallyhidden</span> | Visually hide an element.
| <span class="prop-name">visuallyHidden</span> | <span class="prop-name">.MuiRating-visuallyHidden</span> | Visually hide an element.
| <span class="prop-name">pristine</span> | <span class="prop-name">.MuiRating-pristine</span> | Styles applied to the pristine label.
| <span class="prop-name">label</span> | <span class="prop-name">.MuiRating-label</span> | Styles applied to the label elements.
| <span class="prop-name">icon</span> | <span class="prop-name">.MuiRating-icon</span> | Styles applied to the icon wrapping elements.
Expand Down
3 changes: 1 addition & 2 deletions docs/pages/api-docs/typography.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The `MuiTypography` name can be used for providing [default props](/customizatio
| <span class="prop-name">gutterBottom</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the text will have a bottom margin. |
| <span class="prop-name">noWrap</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the text will not wrap, but instead will truncate with a text overflow ellipsis.<br>Note that text overflow can only happen with block or inline-block level elements (the element needs to have a width in order to overflow). |
| <span class="prop-name">paragraph</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the text will have a bottom margin. |
| <span class="prop-name">variant</span> | <span class="prop-type">'h1'<br>&#124;&nbsp;'h2'<br>&#124;&nbsp;'h3'<br>&#124;&nbsp;'h4'<br>&#124;&nbsp;'h5'<br>&#124;&nbsp;'h6'<br>&#124;&nbsp;'subtitle1'<br>&#124;&nbsp;'subtitle2'<br>&#124;&nbsp;'body1'<br>&#124;&nbsp;'body2'<br>&#124;&nbsp;'caption'<br>&#124;&nbsp;'button'<br>&#124;&nbsp;'overline'<br>&#124;&nbsp;'srOnly'<br>&#124;&nbsp;'inherit'</span> | <span class="prop-default">'body1'</span> | Applies the theme typography styles. |
| <span class="prop-name">variant</span> | <span class="prop-type">'h1'<br>&#124;&nbsp;'h2'<br>&#124;&nbsp;'h3'<br>&#124;&nbsp;'h4'<br>&#124;&nbsp;'h5'<br>&#124;&nbsp;'h6'<br>&#124;&nbsp;'subtitle1'<br>&#124;&nbsp;'subtitle2'<br>&#124;&nbsp;'body1'<br>&#124;&nbsp;'body2'<br>&#124;&nbsp;'caption'<br>&#124;&nbsp;'button'<br>&#124;&nbsp;'overline'<br>&#124;&nbsp;'inherit'</span> | <span class="prop-default">'body1'</span> | Applies the theme typography styles. |
| <span class="prop-name">variantMapping</span> | <span class="prop-type">object</span> | <span class="prop-default">{ h1: 'h1', h2: 'h2', h3: 'h3', h4: 'h4', h5: 'h5', h6: 'h6', subtitle1: 'h6', subtitle2: 'h6', body1: 'p', body2: 'p',}</span> | The component maps the variant prop to a range of different HTML element types. For instance, subtitle1 to `<h6>`. If you wish to change that mapping, you can provide your own. Alternatively, you can use the `component` prop. |

The `ref` is forwarded to the root element.
Expand All @@ -62,7 +62,6 @@ Any other props supplied will be provided to the root element (native element).
| <span class="prop-name">subtitle1</span> | <span class="prop-name">.MuiTypography-subtitle1</span> | Styles applied to the root element if `variant="subtitle1"`.
| <span class="prop-name">subtitle2</span> | <span class="prop-name">.MuiTypography-subtitle2</span> | Styles applied to the root element if `variant="subtitle2"`.
| <span class="prop-name">overline</span> | <span class="prop-name">.MuiTypography-overline</span> | Styles applied to the root element if `variant="overline"`.
| <span class="prop-name">srOnly</span> | <span class="prop-name">.MuiTypography-srOnly</span> | Styles applied to the root element if `variant="srOnly"`. Only accessible to screen readers.
| <span class="prop-name">alignLeft</span> | <span class="prop-name">.MuiTypography-alignLeft</span> | Styles applied to the root element if `align="left"`.
| <span class="prop-name">alignCenter</span> | <span class="prop-name">.MuiTypography-alignCenter</span> | Styles applied to the root element if `align="center"`.
| <span class="prop-name">alignRight</span> | <span class="prop-name">.MuiTypography-alignRight</span> | Styles applied to the root element if `align="right"`.
Expand Down
20 changes: 20 additions & 0 deletions docs/pages/system/screen-readers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'system/screen-readers';
const requireDemo = require.context('docs/src/pages/system/screen-readers', false, /\.(js|tsx)$/);
const requireRaw = require.context(
'!raw-loader!../../src/pages/system/screen-readers',
false,
/\.(js|md|tsx)$/,
);

export default function Page({ demos, docs }) {
return <MarkdownDocs demos={demos} docs={docs} requireDemo={requireDemo} />;
}

Page.getInitialProps = () => {
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw });
return { demos, docs };
};
1 change: 1 addition & 0 deletions docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const pages = [
{ pathname: '/system/shadows' },
{ pathname: '/system/sizing' },
{ pathname: '/system/spacing' },
{ pathname: '/system/screen-readers' },
{ pathname: '/system/typography' },
{ pathname: '/system/api', title: 'API' },
],
Expand Down
7 changes: 5 additions & 2 deletions docs/src/pages/components/icons/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,15 @@ If your icons have semantic meaning, you need to provide a text alternative only

```jsx
import Icon from '@material-ui/core/Icon';
import Typography from '@material-ui/core/Typography';
import { visuallyHidden } from '@material-ui/system';
import { makeStyles } from '@material-ui/core/styles';

const classes = makeStyles({ visuallyHidden })();

// ...

<Icon>add_circle</Icon>
<Typography variant="srOnly">Create a user</Typography>
<span className={classes.visuallyHidden}>Create a user</span>
```

### Reference
Expand Down
16 changes: 4 additions & 12 deletions docs/src/pages/components/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import DeleteIcon from '@material-ui/icons/Delete';
import FilterListIcon from '@material-ui/icons/FilterList';
import { visuallyHidden } from '@material-ui/system';

function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
Expand Down Expand Up @@ -106,7 +107,7 @@ function EnhancedTableHead(props) {
>
{headCell.label}
{orderBy === headCell.id ? (
<span className={classes.visuallyHidden}>
<span className={classes.sortSpan}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
Expand Down Expand Up @@ -200,17 +201,8 @@ const useStyles = makeStyles((theme) => ({
table: {
minWidth: 750,
},
visuallyHidden: {
border: 0,
clip: 'rect(0 0 0 0)',
height: 1,
margin: -1,
overflow: 'hidden',
padding: 0,
position: 'absolute',
top: 20,
width: 1,
},
// TODO fix #20379.
sortSpan: visuallyHidden,
}));

export default function EnhancedTable() {
Expand Down
17 changes: 5 additions & 12 deletions docs/src/pages/components/tables/EnhancedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import DeleteIcon from '@material-ui/icons/Delete';
import FilterListIcon from '@material-ui/icons/FilterList';
import { visuallyHidden } from '@material-ui/system';
import { CSSProperties } from '@material-ui/styles';

interface Data {
calories: number;
Expand Down Expand Up @@ -141,7 +143,7 @@ function EnhancedTableHead(props: EnhancedTableProps) {
>
{headCell.label}
{orderBy === headCell.id ? (
<span className={classes.visuallyHidden}>
<span className={classes.sortSpan}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
Expand Down Expand Up @@ -227,17 +229,8 @@ const useStyles = makeStyles((theme: Theme) =>
table: {
minWidth: 750,
},
visuallyHidden: {
border: 0,
clip: 'rect(0 0 0 0)',
height: 1,
margin: -1,
overflow: 'hidden',
padding: 0,
position: 'absolute',
top: 20,
width: 1,
},
// TODO fix #20379.
sortSpan: visuallyHidden as CSSProperties,
}),
);

Expand Down
21 changes: 18 additions & 3 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Migration from v3 to v4
# Migration from v4 to v5

<p class="description">Yeah, v4 has been released!</p>
<p class="description">Yeah, v5 has been released!</p>

Looking for the v4 docs? [Find them here](https://material-ui.com/versions/).

Expand Down Expand Up @@ -54,4 +54,19 @@ yarn add @material-ui/core
- background-color: #f00;
+ border-color: #f00;
}
```
```

### Typography

- [Typography] Replace `srOnly` prop support with a style util:

```diff
-import Typography from '@material-ui/core/Typography';
+import { visuallyHidden } from '@material-ui/system';
+import styled from 'styled-component';

+const Span = styled('span')(visuallyHidden);

-<Typography variant="srOnly">Create a user</Typography>
+<Span>Create a user</Span>
```
21 changes: 21 additions & 0 deletions docs/src/pages/system/screen-readers/VisuallyHiddenUsage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import Link from '@material-ui/core/Link';
import { visuallyHidden } from '@material-ui/system';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
// TODO fix #20379.
span: visuallyHidden,
});

export default function VisuallyHiddenUsage() {
const classes = useStyles();

return (
<Link href="#foo">
Read more
{/* always visually hidden because the parent is focusable element */}
<span className={classes.span}>about how to visually hide elements</span>
</Link>
);
}
22 changes: 22 additions & 0 deletions docs/src/pages/system/screen-readers/VisuallyHiddenUsage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import Link from '@material-ui/core/Link';
import { visuallyHidden } from '@material-ui/system';
import { makeStyles } from '@material-ui/core/styles';
import { CSSProperties } from '@material-ui/styles';

const useStyles = makeStyles({
// TODO fix #20379.
span: visuallyHidden as CSSProperties,
});

export default function VisuallyHiddenUsage() {
const classes = useStyles();

return (
<Link href="#foo">
Read more
{/* always visually hidden because the parent is focusable element */}
<span className={classes.span}>about how to visually hide elements</span>
</Link>
);
}
13 changes: 13 additions & 0 deletions docs/src/pages/system/screen-readers/screen-readers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Screen readers

<p class="description">Collection of utilities for improving accessibility with screen readers.</p>

## Visually hidden elements

The visually hidden style utility provides a common mechanism for hidings elements visually, but making them available for the assistive technology.

### Usage

The visually hidden style utility can help provide context to read more links.

{{"demo": "pages/system/screen-readers/VisuallyHiddenUsage.js"}}
2 changes: 0 additions & 2 deletions framer/Material-UI.framerfx/code/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface Props {
| 'caption'
| 'button'
| 'overline'
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
| 'srOnly'
| 'inherit';
label?: string;
width?: number;
Expand Down Expand Up @@ -93,7 +92,6 @@ addPropertyControls(Typography, {
'caption',
'button',
'overline',
'srOnly',
'inherit',
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Rating/Rating.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type RatingClassKey =
| 'readOnly'
| 'disabled'
| 'focusVisible'
| 'visuallyhidden'
| 'visuallyHidden'
| 'pristine'
| 'label'
| 'icon'
Expand Down
22 changes: 6 additions & 16 deletions packages/material-ui-lab/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
useControlled,
unstable_useId as useId,
} from '@material-ui/core/utils';
import { visuallyHidden } from '@material-ui/system';
import Star from '../internal/svg-icons/Star';

function clamp(value, min, max) {
Expand Down Expand Up @@ -71,18 +72,7 @@ export const styles = (theme) => ({
/* Pseudo-class applied to the root element if keyboard focused. */
focusVisible: {},
/* Visually hide an element. */
visuallyhidden: {
border: 0,
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
clip: 'rect(0 0 0 0)',
height: 1,
margin: -1,
color: '#000',
overflow: 'hidden',
padding: 0,
position: 'absolute',
top: 20,
width: 1,
},
visuallyHidden,
/* Styles applied to the pristine label. */
pristine: {
'input:focus + &': {
Expand Down Expand Up @@ -342,7 +332,7 @@ const Rating = React.forwardRef(function Rating(props, ref) {
<React.Fragment key={state.value}>
<label className={classes.label} htmlFor={id} {...labelProps}>
{container}
<span className={classes.visuallyhidden}>{getLabelText(state.value)}</span>
<span className={classes.visuallyHidden}>{getLabelText(state.value)}</span>
</label>
<input
onFocus={handleFocus}
Expand All @@ -355,7 +345,7 @@ const Rating = React.forwardRef(function Rating(props, ref) {
type="radio"
name={name}
checked={state.checked}
className={classes.visuallyhidden}
className={classes.visuallyHidden}
/>
</React.Fragment>
);
Expand Down Expand Up @@ -444,10 +434,10 @@ const Rating = React.forwardRef(function Rating(props, ref) {
type="radio"
name={name}
defaultChecked
className={classes.visuallyhidden}
className={classes.visuallyHidden}
/>
<label className={classes.pristine} htmlFor={`${name}-empty`}>
<span className={classes.visuallyhidden}>{emptyLabelText}</span>
<span className={classes.visuallyHidden}>{emptyLabelText}</span>
</label>
</React.Fragment>
)}
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui-system/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as CSS from 'csstype';

// disable automatic export
export {};

Expand Down Expand Up @@ -202,5 +201,7 @@ export const typography: SimpleStyleFunction<
>;
export type TypographyProps = PropsFor<typeof typography>;

export const visuallyHidden: CSS.Properties;
mnajdova marked this conversation as resolved.
Show resolved Hide resolved

// utils
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
1 change: 1 addition & 0 deletions packages/material-ui-system/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './spacing';
export { default as style } from './style';
export { default as typography } from './typography';
export * from './typography';
export { default as visuallyHidden } from './visuallyHidden';
13 changes: 13 additions & 0 deletions packages/material-ui-system/src/visuallyHidden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const visuallyHidden = {
border: 0,
clip: 'rect(0 0 0 0)',
height: 1,
margin: -1,
overflow: 'hidden',
padding: 0,
position: 'absolute',
whiteSpace: 'nowrap',
width: 1,
};

export default visuallyHidden;
5 changes: 1 addition & 4 deletions packages/material-ui/src/Typography/Typography.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as React from 'react';
import { StandardProps, PropTypes } from '..';
import { OverrideProps, OverridableTypeMap, OverridableComponent } from '../OverridableComponent';
import { Variant as ThemeVariant } from '../styles/createTypography';

type Variant = ThemeVariant | 'srOnly';
import { Variant } from '../styles/createTypography';

export interface TypographyTypeMap<P = {}, D extends React.ElementType = 'span'> {
props: P & {
Expand Down Expand Up @@ -64,7 +62,6 @@ export type TypographyClassKey =
| 'caption'
| 'button'
| 'overline'
| 'srOnly'
| 'alignLeft'
| 'alignCenter'
| 'alignRight'
Expand Down
8 changes: 0 additions & 8 deletions packages/material-ui/src/Typography/Typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ export const styles = (theme) => ({
subtitle2: theme.typography.subtitle2,
/* Styles applied to the root element if `variant="overline"`. */
overline: theme.typography.overline,
/* Styles applied to the root element if `variant="srOnly"`. Only accessible to screen readers. */
srOnly: {
position: 'absolute',
height: 1,
width: 1,
overflow: 'hidden',
},
/* Styles applied to the root element if `align="left"`. */
alignLeft: {
textAlign: 'left',
Expand Down Expand Up @@ -233,7 +226,6 @@ Typography.propTypes = {
'caption',
'button',
'overline',
'srOnly',
'inherit',
]),
/**
Expand Down