diff --git a/docs/src/pages/demos/buttons/ButtonBases.js b/docs/src/pages/demos/buttons/ButtonBases.js index a2ed976c49e437..ce1a4c5adde167 100644 --- a/docs/src/pages/demos/buttons/ButtonBases.js +++ b/docs/src/pages/demos/buttons/ButtonBases.js @@ -18,19 +18,20 @@ const styles = theme => ({ width: '100% !important', // Overrides inline-style height: 100, }, - '&:hover': { + '&:hover, &$focusVisible': { zIndex: 1, - }, - '&:hover $imageBackdrop': { - opacity: 0.15, - }, - '&:hover $imageMarked': { - opacity: 0, - }, - '&:hover $imageTitle': { - border: '4px solid currentColor', + '& $imageBackdrop': { + opacity: 0.15, + }, + '& $imageMarked': { + opacity: 0, + }, + '& $imageTitle': { + border: '4px solid currentColor', + }, }, }, + focusVisible: {}, imageButton: { position: 'absolute', left: 0, @@ -104,6 +105,7 @@ function ButtonBases(props) { focusRipple key={image.title} className={classes.image} + focusVisibleClassName={classes.focusVisible} style={{ width: image.width, }} diff --git a/packages/material-ui/src/AppBar/AppBar.d.ts b/packages/material-ui/src/AppBar/AppBar.d.ts index 679f5f6b663f6c..fa5ca4a3f06676 100644 --- a/packages/material-ui/src/AppBar/AppBar.d.ts +++ b/packages/material-ui/src/AppBar/AppBar.d.ts @@ -1,5 +1,5 @@ import { PropTypes, StandardProps } from '..'; -import { PaperProps, PaperClassKey } from '../Paper'; +import { PaperProps } from '../Paper'; export interface AppBarProps extends StandardProps { color?: PropTypes.Color; @@ -7,7 +7,7 @@ export interface AppBarProps extends StandardProps { } export type AppBarClassKey = - | PaperClassKey + | 'root' | 'positionFixed' | 'positionAbsolute' | 'positionSticky' diff --git a/packages/material-ui/src/BottomNavigation/BottomNavigationAction.d.ts b/packages/material-ui/src/BottomNavigation/BottomNavigationAction.d.ts index bb2307f3591e0f..9a891c40808096 100644 --- a/packages/material-ui/src/BottomNavigation/BottomNavigationAction.d.ts +++ b/packages/material-ui/src/BottomNavigation/BottomNavigationAction.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface BottomNavigationActionProps extends StandardProps { @@ -13,12 +13,7 @@ export interface BottomNavigationActionProps value?: any; } -export type BottomNavigationActionClassKey = - | ButtonBaseClassKey - | 'selected' - | 'iconOnly' - | 'wrapper' - | 'label'; +export type BottomNavigationActionClassKey = 'root' | 'selected' | 'iconOnly' | 'wrapper' | 'label'; declare const BottomNavigationAction: React.ComponentType; diff --git a/packages/material-ui/src/Button/Button.d.ts b/packages/material-ui/src/Button/Button.d.ts index 6ff17777e511bc..664de5cfb9d1a2 100644 --- a/packages/material-ui/src/Button/Button.d.ts +++ b/packages/material-ui/src/Button/Button.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps, PropTypes } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface ButtonProps extends StandardProps { color?: PropTypes.Color; @@ -17,13 +17,13 @@ export interface ButtonProps extends StandardProps ({ color: theme.palette.getContrastText(theme.palette.grey[300]), backgroundColor: theme.palette.grey[300], boxShadow: theme.shadows[2], - '&$keyboardFocused': { + '&$focusVisible': { boxShadow: theme.shadows[6], }, '&:active': { @@ -113,7 +113,7 @@ export const styles = theme => ({ }, }, }, - keyboardFocused: {}, + focusVisible: {}, disabled: {}, fab: { borderRadius: '50%', @@ -157,6 +157,7 @@ function Button(props) { disabled, disableFocusRipple, fullWidth, + focusVisibleClassName, mini, size, variant, @@ -189,9 +190,7 @@ function Button(props) { className={className} disabled={disabled} focusRipple={!disableFocusRipple} - classes={{ - keyboardFocused: classes.keyboardFocused, - }} + focusVisibleClassName={classNames(classes.focusVisible, focusVisibleClassName)} {...other} > {children} @@ -235,6 +234,10 @@ Button.propTypes = { * If `true`, the ripple effect will be disabled. */ disableRipple: PropTypes.bool, + /** + * @ignore + */ + focusVisibleClassName: PropTypes.string, /** * If `true`, the button will take up the full width of its container. */ diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.d.ts b/packages/material-ui/src/ButtonBase/ButtonBase.d.ts index 2169fcbb031d7e..5d3af4a6995352 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.d.ts +++ b/packages/material-ui/src/ButtonBase/ButtonBase.d.ts @@ -12,11 +12,12 @@ export interface ButtonBaseProps component?: React.ReactType; disableRipple?: boolean; focusRipple?: boolean; + focusVisibleClassName?: string; onKeyboardFocus?: React.FocusEventHandler; TouchRippleProps?: Partial; } -export type ButtonBaseClassKey = 'root' | 'disabled' | 'keyboardFocused'; +export type ButtonBaseClassKey = 'root' | 'disabled'; declare const ButtonBase: React.ComponentType; diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.js b/packages/material-ui/src/ButtonBase/ButtonBase.js index 7f498e3a4c8c8a..579549093120fc 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.js +++ b/packages/material-ui/src/ButtonBase/ButtonBase.js @@ -41,7 +41,6 @@ export const styles = { }, }, disabled: {}, - keyboardFocused: {}, }; /** @@ -51,18 +50,18 @@ export const styles = { */ class ButtonBase extends React.Component { static getDerivedStateFromProps(nextProps, prevState) { - if (typeof prevState.keyboardFocused === 'undefined') { + if (typeof prevState.focusVisible === 'undefined') { return { - keyboardFocused: false, + focusVisible: false, lastDisabled: nextProps.disabled, }; } // The blur won't fire when the disabled state is set on a focused input. // We need to book keep the focused state manually. - if (!prevState.prevState && nextProps.disabled && prevState.keyboardFocused) { + if (!prevState.prevState && nextProps.disabled && prevState.focusVisible) { return { - keyboardFocused: false, + focusVisible: false, lastDisabled: nextProps.disabled, }; } @@ -83,8 +82,8 @@ class ButtonBase extends React.Component { if ( this.props.focusRipple && !this.props.disableRipple && - !prevState.keyboardFocused && - this.state.keyboardFocused + !prevState.focusVisible && + this.state.focusVisible ) { this.ripple.pulsate(); } @@ -97,7 +96,7 @@ class ButtonBase extends React.Component { onKeyboardFocusHandler = event => { this.keyDown = false; - this.setState({ keyboardFocused: true }); + this.setState({ focusVisible: true }); if (this.props.onKeyboardFocus) { this.props.onKeyboardFocus(event); @@ -120,13 +119,7 @@ class ButtonBase extends React.Component { const key = keycode(event); // Check if key is already down to avoid repeats being counted as multiple activations - if ( - focusRipple && - !this.keyDown && - this.state.keyboardFocused && - this.ripple && - key === 'space' - ) { + if (focusRipple && !this.keyDown && this.state.focusVisible && this.ripple && key === 'space') { this.keyDown = true; event.persist(); this.ripple.stop(event, () => { @@ -157,7 +150,7 @@ class ButtonBase extends React.Component { this.props.focusRipple && keycode(event) === 'space' && this.ripple && - this.state.keyboardFocused + this.state.focusVisible ) { this.keyDown = false; event.persist(); @@ -170,15 +163,15 @@ class ButtonBase extends React.Component { handleMouseDown = createRippleHandler(this, 'MouseDown', 'start', () => { clearTimeout(this.keyboardFocusTimeout); - if (this.state.keyboardFocused) { - this.setState({ keyboardFocused: false }); + if (this.state.focusVisible) { + this.setState({ focusVisible: false }); } }); handleMouseUp = createRippleHandler(this, 'MouseUp', 'stop'); handleMouseLeave = createRippleHandler(this, 'MouseLeave', 'stop', event => { - if (this.state.keyboardFocused) { + if (this.state.focusVisible) { event.preventDefault(); } }); @@ -191,8 +184,8 @@ class ButtonBase extends React.Component { handleBlur = createRippleHandler(this, 'Blur', 'stop', () => { clearTimeout(this.keyboardFocusTimeout); - if (this.state.keyboardFocused) { - this.setState({ keyboardFocused: false }); + if (this.state.focusVisible) { + this.setState({ focusVisible: false }); } }); @@ -227,6 +220,7 @@ class ButtonBase extends React.Component { disabled, disableRipple, focusRipple, + focusVisibleClassName, onBlur, onFocus, onKeyboardFocus, @@ -248,7 +242,7 @@ class ButtonBase extends React.Component { classes.root, { [classes.disabled]: disabled, - [classes.keyboardFocused]: this.state.keyboardFocused, + [focusVisibleClassName]: this.state.focusVisible, }, classNameProp, ); @@ -340,6 +334,13 @@ ButtonBase.propTypes = { * `disableRipple` must also be `false`. */ focusRipple: PropTypes.bool, + /** + * This property can help a person know which element has the keyboard focus. + * The class name will be applied when the element gain the focus throught a keyboard interaction. + * It's a polyfill for the [CSS :focus-visible feature](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo). + * The rational for using this feature [is explain here](https://github.com/WICG/focus-visible/blob/master/explainer.md). + */ + focusVisibleClassName: PropTypes.string, /** * @ignore */ diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.test.js b/packages/material-ui/src/ButtonBase/ButtonBase.test.js index 074166ee380e21..b7ee7010de5203 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.test.js +++ b/packages/material-ui/src/ButtonBase/ButtonBase.test.js @@ -143,7 +143,7 @@ describe('', () => { it('should not have a focus ripple by default', () => { wrapper.instance().ripple = { pulsate: spy() }; - wrapper.setState({ keyboardFocused: true }); + wrapper.setState({ focusVisible: true }); assert.strictEqual( wrapper.instance().ripple.pulsate.callCount, @@ -245,9 +245,9 @@ describe('', () => { assert.strictEqual(ripple.length, 1, 'should have one TouchRipple'); }); - it('should pulsate the ripple when keyboardFocused', () => { + it('should pulsate the ripple when focusVisible', () => { wrapper.instance().ripple = { pulsate: spy() }; - wrapper.setState({ keyboardFocused: true }); + wrapper.setState({ focusVisible: true }); assert.strictEqual( wrapper.instance().ripple.pulsate.callCount, @@ -306,7 +306,7 @@ describe('', () => { ); }); - it('should stop on blur and set keyboardFocused to false', () => { + it('should stop on blur and set focusVisible to false', () => { wrapper.instance().ripple = { stop: spy() }; wrapper.simulate('blur', {}); @@ -315,7 +315,7 @@ describe('', () => { 1, 'should call stop on the ripple', ); - assert.strictEqual(wrapper.state().keyboardFocused, false, 'should not be keyboardFocused'); + assert.strictEqual(wrapper.state().focusVisible, false, 'should not be focusVisible'); }); }); @@ -350,13 +350,13 @@ describe('', () => { it('should detect the keyboard', () => { assert.strictEqual( - wrapper.state().keyboardFocused, + wrapper.state().focusVisible, false, 'should not set keyboard focus before time has passed', ); clock.tick(instance.keyboardFocusCheckTime * instance.keyboardFocusMaxCheckTimes); assert.strictEqual( - wrapper.state().keyboardFocused, + wrapper.state().focusVisible, true, 'should listen for tab presses and set keyboard focus', ); @@ -364,27 +364,23 @@ describe('', () => { it('should ignore the keyboard after 1s', () => { clock.tick(instance.keyboardFocusCheckTime * instance.keyboardFocusMaxCheckTimes); - assert.strictEqual( - wrapper.state().keyboardFocused, - true, - 'should think it is keyboard based', - ); + assert.strictEqual(wrapper.state().focusVisible, true, 'should think it is keyboard based'); button.blur(); - assert.strictEqual(wrapper.state().keyboardFocused, false, 'should has lost the focus'); + assert.strictEqual(wrapper.state().focusVisible, false, 'should has lost the focus'); button.focus(); clock.tick(instance.keyboardFocusCheckTime * instance.keyboardFocusMaxCheckTimes); assert.strictEqual( - wrapper.state().keyboardFocused, + wrapper.state().focusVisible, true, 'should still think it is keyboard based', ); clock.tick(1e3); button.blur(); - assert.strictEqual(wrapper.state().keyboardFocused, false, 'should has lost the focus'); + assert.strictEqual(wrapper.state().focusVisible, false, 'should has lost the focus'); button.focus(); clock.tick(instance.keyboardFocusCheckTime * instance.keyboardFocusMaxCheckTimes); assert.strictEqual( - wrapper.state().keyboardFocused, + wrapper.state().focusVisible, false, 'should stop think it is keyboard based', ); @@ -408,14 +404,14 @@ describe('', () => { it('should reset the focused state', () => { const wrapper = shallow(Hello); - // We simulate a keyboardFocused button that is getting disabled. + // We simulate a focusVisible button that is getting disabled. wrapper.setState({ - keyboardFocused: true, + focusVisible: true, }); wrapper.setProps({ disabled: true, }); - assert.strictEqual(wrapper.state().keyboardFocused, false); + assert.strictEqual(wrapper.state().focusVisible, false); }); it('should not apply disabled on a span', () => { @@ -508,7 +504,7 @@ describe('', () => { , ); wrapper.setProps({ focusRipple: true }); - wrapper.setState({ keyboardFocused: true }); + wrapper.setState({ focusVisible: true }); const eventPersistSpy = spy(); event = { persist: eventPersistSpy, keyCode: keycode('space') }; @@ -597,7 +593,7 @@ describe('', () => { assert.strictEqual(wrapper.find(TouchRipple).length, 1); const onKeyDownSpy = spy(); wrapper.setProps({ onKeyDown: onKeyDownSpy, disableRipple: true, focusRipple: true }); - wrapper.setState({ keyboardFocused: true }); + wrapper.setState({ focusVisible: true }); assert.strictEqual(wrapper.find(TouchRipple).length, 0); const eventPersistSpy = spy(); diff --git a/packages/material-ui/src/Dialog/Dialog.d.ts b/packages/material-ui/src/Dialog/Dialog.d.ts index b43f398deeca83..1e041db98bf73b 100644 --- a/packages/material-ui/src/Dialog/Dialog.d.ts +++ b/packages/material-ui/src/Dialog/Dialog.d.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { StandardProps } from '..'; import { PaperProps } from '../Paper'; -import { ModalProps, ModalClassKey } from '../Modal'; +import { ModalProps } from '../Modal'; import { TransitionHandlerProps, TransitionProps } from '../transitions/transition'; export interface DialogProps @@ -16,7 +16,7 @@ export interface DialogProps } export type DialogClassKey = - | ModalClassKey + | 'root' | 'paper' | 'paperWidthXs' | 'paperWidthSm' diff --git a/packages/material-ui/src/Drawer/Drawer.d.ts b/packages/material-ui/src/Drawer/Drawer.d.ts index a44907731bac04..a87f094beaa41c 100644 --- a/packages/material-ui/src/Drawer/Drawer.d.ts +++ b/packages/material-ui/src/Drawer/Drawer.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ModalProps, ModalClassKey } from '../Modal'; +import { ModalProps } from '../Modal'; import { SlideProps } from '../transitions/Slide'; import { PaperProps } from '../Paper'; import { Theme } from '../styles/createMuiTheme'; @@ -25,7 +25,6 @@ export interface DrawerProps } export type DrawerClassKey = - | ModalClassKey | 'docked' | 'paper' | 'paperAnchorLeft' diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.d.ts b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.d.ts index 29812aeb94cf56..7040441f3585e7 100644 --- a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.d.ts +++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.d.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { StandardProps } from '..'; import { CollapseProps } from '../transitions/Collapse'; -import { PaperProps, PaperClassKey } from '../Paper'; +import { PaperProps } from '../Paper'; export interface ExpansionPanelProps extends StandardProps { @@ -12,7 +12,7 @@ export interface ExpansionPanelProps onChange?: (event: React.ChangeEvent<{}>, expanded: boolean) => void; } -export type ExpansionPanelClassKey = PaperClassKey | 'disabled' | 'expanded'; +export type ExpansionPanelClassKey = 'root' | 'expanded' | 'disabled'; declare const ExpansionPanel: React.ComponentType; diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanelSummary.d.ts b/packages/material-ui/src/ExpansionPanel/ExpansionPanelSummary.d.ts index b94ae36dac0c54..922baea5816ce1 100644 --- a/packages/material-ui/src/ExpansionPanel/ExpansionPanelSummary.d.ts +++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanelSummary.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface ExpansionPanelSummaryProps extends StandardProps { @@ -11,7 +11,7 @@ export interface ExpansionPanelSummaryProps } export type ExpansionPanelSummaryClassKey = - | ButtonBaseClassKey + | 'root' | 'expanded' | 'focused' | 'disabled' diff --git a/packages/material-ui/src/IconButton/IconButton.d.ts b/packages/material-ui/src/IconButton/IconButton.d.ts index 01b3c69c7c0224..a6bd70eaa52536 100644 --- a/packages/material-ui/src/IconButton/IconButton.d.ts +++ b/packages/material-ui/src/IconButton/IconButton.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps, PropTypes } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface IconButtonProps extends StandardProps { color?: PropTypes.Color; @@ -9,10 +9,11 @@ export interface IconButtonProps extends StandardProps; diff --git a/packages/material-ui/src/Input/InputLabel.d.ts b/packages/material-ui/src/Input/InputLabel.d.ts index 260e22a329036a..e202623507b9ec 100644 --- a/packages/material-ui/src/Input/InputLabel.d.ts +++ b/packages/material-ui/src/Input/InputLabel.d.ts @@ -13,12 +13,7 @@ export interface InputLabelProps extends StandardProps; diff --git a/packages/material-ui/src/List/ListItem.d.ts b/packages/material-ui/src/List/ListItem.d.ts index 9b30e4f2180e68..0937691fef4762 100644 --- a/packages/material-ui/src/List/ListItem.d.ts +++ b/packages/material-ui/src/List/ListItem.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface ListItemProps extends StandardProps< @@ -19,11 +19,12 @@ export interface ListItemProps } export type ListItemClassKey = - | ButtonBaseClassKey + | 'root' | 'container' - | 'keyboardFocused' + | 'focusVisible' | 'default' | 'dense' + | 'disabled' | 'divider' | 'gutters' | 'button' diff --git a/packages/material-ui/src/List/ListItem.js b/packages/material-ui/src/List/ListItem.js index c07aaef2c7cca8..0675ca66cf59e3 100644 --- a/packages/material-ui/src/List/ListItem.js +++ b/packages/material-ui/src/List/ListItem.js @@ -19,7 +19,7 @@ export const styles = theme => ({ container: { position: 'relative', }, - keyboardFocused: { + focusVisible: { backgroundColor: theme.palette.action.hover, }, default: { @@ -105,9 +105,7 @@ class ListItem extends React.Component { if (button) { componentProps.component = componentProp || 'div'; - componentProps.classes = { - keyboardFocused: classes.keyboardFocused, - }; + componentProps.focusVisibleClassName = classes.focusVisible; Component = ButtonBase; } diff --git a/packages/material-ui/src/Menu/Menu.d.ts b/packages/material-ui/src/Menu/Menu.d.ts index 9083e8b85a0957..a07ba86745327c 100644 --- a/packages/material-ui/src/Menu/Menu.d.ts +++ b/packages/material-ui/src/Menu/Menu.d.ts @@ -1,17 +1,21 @@ import * as React from 'react'; import { PopoverProps, PopoverClassKey } from '../Popover'; import { MenuListProps } from './MenuList'; +import { PaperProps } from '../Paper'; import { StandardProps } from '..'; import { TransitionHandlerProps, TransitionProps } from '../transitions/transition'; +import { ClassNameMap } from '../styles/withStyles'; export interface MenuProps extends StandardProps, MenuClassKey> { anchorEl?: HTMLElement; MenuListProps?: Partial; + PaperProps?: Partial; + PopoverClasses?: Partial>; transitionDuration?: TransitionProps['timeout'] | 'auto'; } -export type MenuClassKey = PopoverClassKey | 'root'; +export type MenuClassKey = 'paper'; declare const Menu: React.ComponentType; diff --git a/packages/material-ui/src/Menu/MenuItem.d.ts b/packages/material-ui/src/Menu/MenuItem.d.ts index 87a33f7302a79e..e15d4f55d09479 100644 --- a/packages/material-ui/src/Menu/MenuItem.d.ts +++ b/packages/material-ui/src/Menu/MenuItem.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ListItemProps, ListItemClassKey } from '../List'; +import { ListItemProps } from '../List'; export interface MenuItemProps extends StandardProps { component?: React.ReactType; @@ -8,7 +8,7 @@ export interface MenuItemProps extends StandardProps; diff --git a/packages/material-ui/src/MobileStepper/MobileStepper.d.ts b/packages/material-ui/src/MobileStepper/MobileStepper.d.ts index 77b189e67e99a2..a6391594a91a3d 100644 --- a/packages/material-ui/src/MobileStepper/MobileStepper.d.ts +++ b/packages/material-ui/src/MobileStepper/MobileStepper.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { PaperProps, PaperClassKey } from '../Paper'; +import { PaperProps } from '../Paper'; import { ButtonProps } from '../Button'; export interface MobileStepperProps extends StandardProps { @@ -13,7 +13,7 @@ export interface MobileStepperProps extends StandardProps { action?: React.ReactElement; message: React.ReactElement | string; } -export type SnackbarContentClassKey = PaperClassKey | 'message' | 'action'; +export type SnackbarContentClassKey = 'root' | 'message' | 'action'; declare const SnackbarContent: React.ComponentType; diff --git a/packages/material-ui/src/Stepper/StepButton.d.ts b/packages/material-ui/src/Stepper/StepButton.d.ts index e51ccd0a4518d5..6e439d9b3cff1e 100644 --- a/packages/material-ui/src/Stepper/StepButton.d.ts +++ b/packages/material-ui/src/Stepper/StepButton.d.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { StandardProps } from '..'; import { Orientation } from './Stepper'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export type StepButtonIcon = React.ReactElement | string | number; @@ -16,7 +16,7 @@ export interface StepButtonProps extends StandardProps; diff --git a/packages/material-ui/src/Stepper/Stepper.d.ts b/packages/material-ui/src/Stepper/Stepper.d.ts index 420fd1988bf7d2..0e149787853aa8 100644 --- a/packages/material-ui/src/Stepper/Stepper.d.ts +++ b/packages/material-ui/src/Stepper/Stepper.d.ts @@ -1,7 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; import { PaperProps } from '../Paper'; -import { PaperClassKey } from '../Paper/Paper'; export type Orientation = 'horizontal' | 'vertical'; @@ -14,12 +13,7 @@ export interface StepperProps extends StandardProps orientation?: Orientation; } -export type StepperClasskey = - | PaperClassKey - | 'root' - | 'horizontal' - | 'vertical' - | 'alternativeLabel'; +export type StepperClasskey = 'root' | 'horizontal' | 'vertical' | 'alternativeLabel'; declare const Stepper: React.ComponentType; diff --git a/packages/material-ui/src/Table/TablePagination.d.ts b/packages/material-ui/src/Table/TablePagination.d.ts index b89c51da5a5a67..c4b319fee6e078 100644 --- a/packages/material-ui/src/Table/TablePagination.d.ts +++ b/packages/material-ui/src/Table/TablePagination.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { TableCellProps, TableCellClassKey } from './TableCell.d'; +import { TableCellProps } from './TableCell.d'; import { IconButtonProps } from '../IconButton/IconButton'; import { SelectProps } from '../Select/Select'; @@ -31,7 +31,7 @@ export interface TablePaginationProps export type TablePaginationBaseProps = TableCellProps; export type TablePaginationClassKey = - | TableCellClassKey + | 'root' | 'toolbar' | 'spacer' | 'caption' diff --git a/packages/material-ui/src/Table/TablePaginationActions.d.ts b/packages/material-ui/src/Table/TablePaginationActions.d.ts index 0cbcf0c2c380c8..4ae44795bb96ed 100644 --- a/packages/material-ui/src/Table/TablePaginationActions.d.ts +++ b/packages/material-ui/src/Table/TablePaginationActions.d.ts @@ -1,10 +1,8 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { TableCellClassKey } from './TableCell.d'; import { IconButtonProps } from '../IconButton/IconButton'; -export interface TablePaginationActionsProps - extends StandardProps, TablePaginationActionsClassKey> { +export interface TablePaginationActionsProps extends React.HTMLAttributes { backIconButtonProps?: Partial; count: number; nextIconButtonProps?: Partial; @@ -13,8 +11,6 @@ export interface TablePaginationActionsProps rowsPerPage: number; } -export type TablePaginationActionsClassKey = 'root'; - declare const TablePaginationActions: React.ComponentType; export default TablePaginationActions; diff --git a/packages/material-ui/src/Table/TableSortLabel.d.ts b/packages/material-ui/src/Table/TableSortLabel.d.ts index 84cb6c50d6ac72..068240183d5327 100644 --- a/packages/material-ui/src/Table/TableSortLabel.d.ts +++ b/packages/material-ui/src/Table/TableSortLabel.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase'; export interface TableSortLabelProps extends StandardProps { @@ -9,7 +9,7 @@ export interface TableSortLabelProps } export type TableSortLabelClassKey = - | ButtonBaseClassKey + | 'root' | 'active' | 'icon' | 'iconDirectionDesc' diff --git a/packages/material-ui/src/Tabs/Tab.d.ts b/packages/material-ui/src/Tabs/Tab.d.ts index 51031f3bace29c..fb9cb6115e19e7 100644 --- a/packages/material-ui/src/Tabs/Tab.d.ts +++ b/packages/material-ui/src/Tabs/Tab.d.ts @@ -1,7 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; import { ButtonBaseProps } from '../ButtonBase'; -import { ButtonBaseClassKey } from '../ButtonBase/ButtonBase'; export interface TabProps extends StandardProps { disabled?: boolean; @@ -17,7 +16,7 @@ export interface TabProps extends StandardProps { @@ -7,7 +7,7 @@ export interface TabScrollButtonProps visible?: boolean; } -export type TabScrollButtonClassKey = ButtonBaseClassKey | 'root'; +export type TabScrollButtonClassKey = 'root'; declare const TabScrollButton: React.ComponentType; diff --git a/packages/material-ui/src/Tabs/Tabs.d.ts b/packages/material-ui/src/Tabs/Tabs.d.ts index 3b7cc37d87b846..b9879cb08e706b 100644 --- a/packages/material-ui/src/Tabs/Tabs.d.ts +++ b/packages/material-ui/src/Tabs/Tabs.d.ts @@ -1,6 +1,6 @@ import * as React from 'react'; import { StandardProps } from '..'; -import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase/ButtonBase'; +import { ButtonBaseProps } from '../ButtonBase/ButtonBase'; export interface TabsProps extends StandardProps { action?: (actions: TabsActions) => void; @@ -18,7 +18,7 @@ export interface TabsProps extends StandardProps', () => { assert.notStrictEqual(markup.match('Hello World'), null); assert.strictEqual(sheetsRegistry.registry.length, 3); assert.strictEqual(sheetsRegistry.toString().length > 4000, true); - assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-19'); + assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-18'); assert.deepEqual( sheetsRegistry.registry[1].classes, { disabled: 'MuiButtonBase-disabled-17', - keyboardFocused: 'MuiButtonBase-keyboardFocused-18', root: 'MuiButtonBase-root-16', }, 'the class names should be deterministic', diff --git a/packages/material-ui/test/typescript/components.spec.tsx b/packages/material-ui/test/typescript/components.spec.tsx index c0e337502a2c96..be358f2953491c 100644 --- a/packages/material-ui/test/typescript/components.spec.tsx +++ b/packages/material-ui/test/typescript/components.spec.tsx @@ -796,9 +796,7 @@ const SelectTest = () => ( ); -const InputAdornmentTest = () => ( - alert('Hello')} /> -); +const InputAdornmentTest = () => alert('Hello')} />; const ResponsiveComponentTest = () => { const ResponsiveComponent = withMobileDialog({ diff --git a/pages/api/button-base.md b/pages/api/button-base.md index 709bf1f04bc7e7..fabed729912b05 100644 --- a/pages/api/button-base.md +++ b/pages/api/button-base.md @@ -22,6 +22,7 @@ It contains a load of style reset and some focus/ripple logic. | disabled | bool | | If `true`, the base button will be disabled. | | disableRipple | bool | false | If `true`, the ripple effect will be disabled. | | focusRipple | bool | false | If `true`, the base button will have a keyboard focus ripple. `disableRipple` must also be `false`. | +| focusVisibleClassName | string | | This property can help a person know which element has the keyboard focus. The class name will be applied when the element gain the focus throught a keyboard interaction. It's a polyfill for the [CSS :focus-visible feature](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo). The rational for using this feature [is explain here](https://github.com/WICG/focus-visible/blob/master/explainer.md). | | onKeyboardFocus | func | | Callback fired when the component is focused with a keyboard. We trigger a `onFocus` callback too. | | TouchRippleProps | object | | Properties applied to the `TouchRipple` element. | @@ -33,7 +34,6 @@ You can override all the class names injected by Material-UI thanks to the `clas This property accepts the following keys: - `root` - `disabled` -- `keyboardFocused` Have a look at [overriding with classes](/customization/overrides#overriding-with-classes) section and the [implementation of the component](https://github.com/mui-org/material-ui/tree/v1-beta/packages/material-ui/src/ButtonBase/ButtonBase.js) diff --git a/pages/api/button.md b/pages/api/button.md index 91c4d41f88d1a5..348f26c968ecc2 100644 --- a/pages/api/button.md +++ b/pages/api/button.md @@ -39,7 +39,7 @@ This property accepts the following keys: - `raised` - `raisedPrimary` - `raisedSecondary` -- `keyboardFocused` +- `focusVisible` - `disabled` - `fab` - `mini` diff --git a/pages/api/list-item.md b/pages/api/list-item.md index 1e95e3a1a810c2..8f9f2a2fbcb117 100644 --- a/pages/api/list-item.md +++ b/pages/api/list-item.md @@ -30,7 +30,7 @@ You can override all the class names injected by Material-UI thanks to the `clas This property accepts the following keys: - `root` - `container` -- `keyboardFocused` +- `focusVisible` - `default` - `dense` - `disabled`