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

[typings] Switch tabIndex from string type to number | string #8115

Merged
merged 2 commits into from
Sep 9, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/pages/demos/lists/CheckboxList.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CheckboxList extends React.Component {
<ListItem dense button key={value} onClick={event => this.handleToggle(event, value)}>
<Checkbox
checked={this.state.checked.indexOf(value) !== -1}
tabIndex="-1"
tabIndex={-1}
disableRipple
/>
<ListItemText primary={`Line item ${value + 1}`} />
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/tables/EnhancedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class EnhancedTable extends React.Component {
onKeyDown={event => this.handleKeyDown(event, n.id)}
role="checkbox"
aria-checked={isSelected}
tabIndex="-1"
tabIndex={-1}
key={n.id}
selected={isSelected}
>
Expand Down
2 changes: 1 addition & 1 deletion src/ButtonBase/ButtonBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ButtonBaseProps {
onTouchEnd?: React.TouchEventHandler<any>;
onTouchStart?: React.TouchEventHandler<any>;
role?: string;
tabIndex?: string;
tabIndex?: number | string;
type?: string;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: string,
tabIndex?: number | string,
/**
* @ignore
*/
Expand All @@ -149,7 +149,7 @@ class ButtonBase extends React.Component<AllProps, State> {
centerRipple: false,
focusRipple: false,
disableRipple: false,
tabIndex: '0',
tabIndex: 0,
type: 'button',
};

Expand Down Expand Up @@ -379,7 +379,7 @@ class ButtonBase extends React.Component<AllProps, State> {
onMouseUp={this.handleMouseUp}
onTouchEnd={this.handleTouchEnd}
onTouchStart={this.handleTouchStart}
tabIndex={disabled ? '-1' : tabIndex}
tabIndex={disabled ? -1 : tabIndex}
className={className}
{...buttonProps}
{...other}
Expand Down
4 changes: 2 additions & 2 deletions src/ButtonBase/ButtonBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('<ButtonBase />', () => {
const wrapper = shallow(<ButtonBase component="span" role="checkbox" aria-checked={false} />);
assert.strictEqual(wrapper.name(), 'span');
assert.strictEqual(wrapper.props().role, 'checkbox', 'should be role checkbox');
assert.strictEqual(wrapper.props().tabIndex, '0', 'should be 0');
assert.strictEqual(wrapper.props().tabIndex, 0, 'should be 0');
});

it('should spread props on button', () => {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('<ButtonBase />', () => {
describe('prop: disabled', () => {
it('should apply the right tabIndex', () => {
const wrapper = shallow(<ButtonBase disabled>Hello</ButtonBase>);
assert.strictEqual(wrapper.props().tabIndex, '-1', 'should not receive the focus');
assert.strictEqual(wrapper.props().tabIndex, -1, 'should not receive the focus');
});

it('should also apply it when using component', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: string,
tabIndex?: number | string,
/**
* The value of the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Chip/Chip.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ChipProps extends React.HTMLAttributes<HTMLDivElement> {
label?: React.ReactNode;
onKeyDown?: React.EventHandler<React.KeyboardEvent<any>>;
onRequestDelete?: React.EventHandler<any>;
tabIndex?: number;
tabIndex?: number | string;
}

export default class Chip extends StyledComponent<ChipProps> {}
2 changes: 1 addition & 1 deletion src/Chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: number,
tabIndex?: number | string,
};

type AllProps = DefaultProps & Props;
Expand Down
4 changes: 2 additions & 2 deletions src/Input/Textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class Textarea extends React.Component<AllProps, State> {
<textarea
ref={this.handleRefSinglelineShadow}
className={classnames(classes.shadow, classes.textarea)}
tabIndex="-1"
tabIndex={-1}
rows="1"
readOnly
aria-hidden="true"
Expand All @@ -226,7 +226,7 @@ class Textarea extends React.Component<AllProps, State> {
<textarea
ref={this.handleRefShadow}
className={classnames(classes.shadow, classes.textarea)}
tabIndex="-1"
tabIndex={-1}
rows={rows}
aria-hidden="true"
readOnly
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function MenuItem(props: AllProps) {
<ListItem
button
role={role}
tabIndex="-1"
tabIndex={-1}
className={className}
component={component}
{...other}
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/MenuItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('<MenuItem />', () => {

it('should have a tabIndex of -1 by default', () => {
const wrapper = shallow(<MenuItem />);
assert.strictEqual(wrapper.props().tabIndex, '-1', 'should have a -1 tabIndex');
assert.strictEqual(wrapper.props().tabIndex, -1, 'should have a -1 tabIndex');
});

describe('event callbacks', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/MenuList.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class MenuList extends React.Component<Props, State> {
}

return React.cloneElement(child, {
tabIndex: index === this.state.currentTabIndex ? '0' : '-1',
tabIndex: index === this.state.currentTabIndex ? 0 : -1,
ref: child.props.selected
? node => {
this.selectedItem = node;
Expand Down
2 changes: 1 addition & 1 deletion src/Radio/Radio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface RadioProps extends SwitchBaseProps {
inputRef?: React.Ref<any>;
name?: string;
onChange?: (event: React.ChangeEvent<{}>, checked: boolean) => void;
tabIndex?: string;
tabIndex?: number | string;
value?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: string,
tabIndex?: number | string,
/**
* The value of the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class SelectInput extends React.Component<AllProps, State> {
classNameProp,
)}
aria-pressed={this.state.open ? 'true' : 'false'}
tabIndex={disabled ? null : '0'}
tabIndex={disabled ? null : 0}
role="button"
aria-owns={this.state.open ? `menu-${name || ''}` : null}
aria-haspopup="true"
Expand Down
2 changes: 1 addition & 1 deletion src/Switch/Switch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SwitchProps extends SwitchBaseProps {
inputProps?: object;
name?: string;
onChange?: (event: React.ChangeEvent<{}>, checked: boolean) => void;
tabIndex?: string;
tabIndex?: number | string;
value?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Switch/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: string,
tabIndex?: number | string,
/**
* The value of the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Tabs/TabScrollButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function TabScrollButton(props) {
}

return (
<ButtonBase className={className} onClick={onClick} tabIndex="-1" {...other}>
<ButtonBase className={className} onClick={onClick} tabIndex={-1} {...other}>
{direction === 'left' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</ButtonBase>
);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class Modal extends React.Component<AllProps, State> {
}

if (tabIndex === undefined) {
childProps.tabIndex = tabIndex == null ? '-1' : tabIndex;
childProps.tabIndex = tabIndex == null ? -1 : tabIndex;
}

let backdropProps;
Expand Down
2 changes: 1 addition & 1 deletion src/internal/SwitchBase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SwitchBaseProps {
inputRef?: React.Ref<any>;
name?: string;
onChange?: (event: React.ChangeEvent<{}>, checked: boolean) => void;
tabIndex?: string;
tabIndex?: number | string;
value?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal/SwitchBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type Props = {
/**
* @ignore
*/
tabIndex?: string,
tabIndex?: number | string,
/**
* The value of the component.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/internal/SwitchBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ describe('<SwitchBase />', () => {
});

it('should pass tabIndex to the input so it can be taken out of focus rotation', () => {
const wrapper = shallow(<SwitchBase tabIndex="-1" />);
const wrapper = shallow(<SwitchBase tabIndex={-1} />);
const input = wrapper.find('input');
assert.strictEqual(input.props().tabIndex, '-1');
assert.strictEqual(input.props().tabIndex, -1);
});

it('should pass value, disabled, checked, and name to the input', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/MenuList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function assertMenuItemTabIndexed(wrapper, tabIndexed) {

items.forEach((item, index) => {
if (index === tabIndexed) {
assert.strictEqual(item.prop('tabIndex'), '0', 'should have the tab index');
assert.strictEqual(item.prop('tabIndex'), 0, 'should have the tab index');
} else {
assert.strictEqual(
item.prop('tabIndex'),
'-1',
-1,
`item at index ${index} should not be tab focusable`,
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/regressions/tests/List/PrimaryActionCheckboxListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export default function PrimaryActionCheckboxListItem() {
return (
<div style={{ background: '#fff', width: 300 }}>
<ListItem button>
<Checkbox tabIndex="-1" disableRipple />
<Checkbox tabIndex={-1} disableRipple />
<ListItemText primary="Primary" />
<ListItemSecondaryAction>
<IconButton>comment</IconButton>
</ListItemSecondaryAction>
</ListItem>
<ListItem button dense>
<Checkbox tabIndex="-1" disableRipple />
<Checkbox tabIndex={-1} disableRipple />
<ListItemText primary="Primary" />
<ListItemSecondaryAction>
<IconButton>comment</IconButton>
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/components.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const ListTest = () => (
key={value}
onClick={(e: React.SyntheticEvent<any>) => log(e)}
>
<Checkbox checked={true} tabIndex="-1" disableRipple />
<Checkbox checked={true} tabIndex={-1} disableRipple />
<ListItemText primary={`Line item ${value + 1}`} />
<ListItemSecondaryAction>
<IconButton aria-label="Comments">
Expand Down