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 10 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
15 changes: 15 additions & 0 deletions docs/pages/api-docs/visually-hidden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'api/visually-hidden';
const requireRaw = require.context('!raw-loader!./', false, /\/visually-hidden\.md$/);

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

Page.getInitialProps = () => {
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw });
return { demos, docs };
};
55 changes: 55 additions & 0 deletions docs/pages/api-docs/visually-hidden.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
filename: /packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js
---

<!--- This documentation is automatically generated, do not try to edit it. -->

# VisuallyHidden API

<p class="description">The API documentation of the VisuallyHidden React component. Learn more about the props and the CSS customization points.</p>

## Import

```js
import VisuallyHidden from '@material-ui/lab/VisuallyHidden';
// or
import { VisuallyHidden } from '@material-ui/lab';
```

You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/).



## Component name

The `MuiVisuallyHidden` name can be used for providing [default props](/customization/globals/#default-props) or [style overrides](/customization/globals/#css) at the theme level.

## Props

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |

The `ref` is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

## CSS

| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiVisuallyHidden-root</span> | Styles applied to the root element.

You can override the style of the component thanks to one of these customization points:

- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes).
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names).
- With a theme and an [`overrides` property](/customization/globals/#css).

If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js) for more detail.

## Demos

- [Visually Hidden](/components/visually-hidden/)

24 changes: 24 additions & 0 deletions docs/pages/components/visually-hidden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'components/visually-hidden';
const requireDemo = require.context(
'docs/src/pages/components/visually-hidden',
false,
/\.(js|tsx)$/,
);
const requireRaw = require.context(
'!raw-loader!../../src/pages/components/visually-hidden',
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 @@ -125,6 +125,7 @@ const pages = [
{ pathname: '/components/timeline' },
{ pathname: '/components/toggle-button' },
{ pathname: '/components/tree-view' },
{ pathname: '/components/visually-hidden' },
],
},
],
Expand Down
13 changes: 2 additions & 11 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/lab/VisuallyHidden';

function createData(name, calories, fat, carbs, protein) {
return { name, calories, fat, carbs, protein };
Expand Down Expand Up @@ -200,17 +201,7 @@ 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,
},
visuallyHidden,
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
}));

export default function EnhancedTable() {
Expand Down
13 changes: 2 additions & 11 deletions docs/src/pages/components/tables/EnhancedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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/lab/VisuallyHidden';
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

interface Data {
calories: number;
Expand Down Expand Up @@ -227,17 +228,7 @@ 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,
},
visuallyHidden,
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
}),
);

Expand Down
15 changes: 15 additions & 0 deletions docs/src/pages/components/visually-hidden/VisuallyHiddenUsage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import VisuallyHidden from '@material-ui/lab/VisuallyHidden';
import IconButton from '@material-ui/core/IconButton';
import AccessibilityIcon from '@material-ui/icons/Accessibility';

export default function VisuallyHiddenUsage() {
return (
<IconButton>
<VisuallyHidden>
This text will not be visible, but will be read by screen readers.
</VisuallyHidden>
<AccessibilityIcon />
</IconButton>
);
}
15 changes: 15 additions & 0 deletions docs/src/pages/components/visually-hidden/VisuallyHiddenUsage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import VisuallyHidden from '@material-ui/lab/VisuallyHidden';
import IconButton from '@material-ui/core/IconButton';
import AccessibilityIcon from '@material-ui/icons/Accessibility';

export default function VisuallyHiddenUsage() {
return (
<IconButton>
<VisuallyHidden>
This text will not be visible, but will be read by screen readers.
</VisuallyHidden>
<AccessibilityIcon />
</IconButton>
);
}
15 changes: 15 additions & 0 deletions docs/src/pages/components/visually-hidden/visually-hidden.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: VisuallyHidden React component
components: VisuallyHidden
---

# VisuallyHidden

<p class="description">The vissually hidden component provides a common technique that is used on the web for hidings some elements visually from the clients, but making them available for the screen readers and other assistive technology.</p>
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved


## Usage

The text in the example will not be shown visually, but will be read by screen readers.

{{"demo": "pages/components/visually-hidden/VisuallyHiddenUsage.js"}}
14 changes: 2 additions & 12 deletions packages/material-ui-lab/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
unstable_useId as useId,
} from '@material-ui/core/utils';
import Star from '../internal/svg-icons/Star';
import { visuallyHidden } from '../VisuallyHidden';

function clamp(value, min, max) {
if (value < min) {
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: visuallyHidden,
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
/* Styles applied to the pristine label. */
pristine: {
'input:focus + &': {
Expand Down
26 changes: 26 additions & 0 deletions packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react';
import { StandardProps } from '@material-ui/core';
import { CSSProperties } from '@material-ui/styles';

export interface VisuallyHiddenProps extends StandardProps<{}, VisuallyHiddenClassKey> {
/**
* The content of the component.
*/
children?: React.ReactNode;
}

export type VisuallyHiddenClassKey = 'root';

export const visuallyHidden: CSSProperties;

/**
*
* Demos:
*
* - [Visually Hidden](https://material-ui.com/components/visually-hidden/)
*
* API:
*
* - [VisuallyHidden API](https://material-ui.com/api/visually-hidden/)
*/
export default function VisuallyHidden(props: VisuallyHiddenProps): JSX.Element;
49 changes: 49 additions & 0 deletions packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { withStyles } from '@material-ui/core/styles';

export 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 const styles = () => ({
/* Styles applied to the root element. */
root: visuallyHidden,
});

const VisuallyHidden = React.forwardRef(function VisuallyHidden(props, ref) {
const { classes, className, ...other } = props;

return <span className={clsx(classes.root, className)} ref={ref} {...other} />;
});

VisuallyHidden.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the d.ts file and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
};

export default withStyles(styles, { name: 'MuiVisuallyHidden' })(VisuallyHidden);
22 changes: 22 additions & 0 deletions packages/material-ui-lab/src/VisuallyHidden/VisuallyHidden.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import { getClasses } from '@material-ui/core/test-utils';
import createMount from 'test/utils/createMount';
import describeConformance from '@material-ui/core/test-utils/describeConformance';
import VisuallyHidden from './VisuallyHidden';

describe('<VisuallyHidden />', () => {
const mount = createMount();
let classes;

before(() => {
classes = getClasses(<VisuallyHidden />);
});

describeConformance(<VisuallyHidden />, () => ({
classes,
inheritComponent: 'span',
mount,
refInstanceof: window.HTMLSpanElement,
skip: ['componentProp'],
}));
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
});
2 changes: 2 additions & 0 deletions packages/material-ui-lab/src/VisuallyHidden/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './VisuallyHidden';
export * from './VisuallyHidden';
1 change: 1 addition & 0 deletions packages/material-ui-lab/src/VisuallyHidden/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, visuallyHidden } from './VisuallyHidden';
3 changes: 3 additions & 0 deletions packages/material-ui-lab/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ export * from './TreeView';

export { default as useAutocomplete } from './useAutocomplete';
export * from './useAutocomplete';

export { default as VisuallyHidden } from './VisuallyHidden';
export * from './VisuallyHidden';
3 changes: 3 additions & 0 deletions packages/material-ui-lab/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ export * from './TreeView';

// createFilterOptions is exported from Autocomplete
export { default as useAutocomplete } from './useAutocomplete';

export { default as VisuallyHidden } from './VisuallyHidden';
export * from './VisuallyHidden';