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

chore(card): add keyboard interaction a11y test, clean up docs #5082

Merged
merged 1 commit into from
Nov 5, 2020
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
52 changes: 26 additions & 26 deletions packages/react-core/src/components/Card/examples/Card.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ propComponents: ['Card', 'CardHeaderMain', 'CardTitle', 'CardBody', 'CardFooter'
ouia: true
---

import pfLogo from './pfLogo.svg';
import pfLogo from './pfLogo.svg';

## Examples
### Basic
Expand All @@ -24,8 +24,8 @@ import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
### With image and actions
```js
import React from 'react';
import { Brand, Card, CardHeader, CardHeaderMain, CardActions, CardTitle, CardBody, CardFooter, Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle } from '@patternfly/react-core';
import pfLogo from './pfLogo.svg';
import { Brand, Card, CardHeader, CardHeaderMain, CardActions, CardTitle, CardBody, CardFooter, Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, KebabToggle } from '@patternfly/react-core';
import pfLogo from './pfLogo.svg';

class KebabDropdown extends React.Component {
constructor(props) {
Expand All @@ -45,11 +45,11 @@ class KebabDropdown extends React.Component {
});
};
this.onClick = (checked, event) => {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
}

render() {
Expand Down Expand Up @@ -107,7 +107,7 @@ class KebabDropdown extends React.Component {
### Card header in card head
```js
import React from 'react';
import { Card, CardHeader, CardActions, CardTitle, CardBody, CardFooter, Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle } from '@patternfly/react-core';
import { Card, CardHeader, CardActions, CardTitle, CardBody, CardFooter, Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, KebabToggle } from '@patternfly/react-core';

class KebabDropdown extends React.Component {
constructor(props) {
Expand All @@ -127,11 +127,11 @@ class KebabDropdown extends React.Component {
});
};
this.onClick = (checked, event) => {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
}

render() {
Expand Down Expand Up @@ -186,7 +186,7 @@ class KebabDropdown extends React.Component {
### Only actions in card head (no header/footer)
```js
import React from 'react';
import { Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle, Card, CardHeader, CardActions, CardTitle, CardBody } from '@patternfly/react-core';
import { Checkbox, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, KebabToggle, Card, CardHeader, CardActions, CardTitle, CardBody } from '@patternfly/react-core';

class KebabDropdown extends React.Component {
constructor(props) {
Expand All @@ -206,11 +206,11 @@ class KebabDropdown extends React.Component {
});
};
this.onClick = (checked, event) => {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({ [name]: value });
};
}

render() {
Expand Down Expand Up @@ -270,7 +270,7 @@ import { Brand, Card, CardBody, CardFooter, CardHeader, CardHeaderMain, CardTitl
<CardHeaderMain>
<Brand src={pfLogo} alt="PatternFly logo" style={{ height: '50px' }}/>
</CardHeaderMain>
</CardHeader>
</CardHeader>
<CardTitle>Header</CardTitle>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
Expand All @@ -280,7 +280,7 @@ import { Brand, Card, CardBody, CardFooter, CardHeader, CardHeaderMain, CardTitl
### With no footer
```js
import React from 'react';
import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
import { Card, CardTitle, CardBody } from '@patternfly/react-core';

<Card>
<CardTitle>Header</CardTitle>
Expand All @@ -291,7 +291,7 @@ import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
### With no header
```js
import React from 'react';
import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
import { Card, CardBody, CardFooter } from '@patternfly/react-core';

<Card>
<CardBody>This card has no header</CardBody>
Expand All @@ -302,7 +302,7 @@ import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
### With only a content section
```js
import React from 'react';
import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
import { Card, CardBody } from '@patternfly/react-core';

<Card>
<CardBody>Body</CardBody>
Expand Down Expand Up @@ -364,7 +364,7 @@ import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
### Selectable and selected
```js
import React from 'react';
import { Card, CardHeader, CardActions, CardTitle, CardBody, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection, KebabToggle, } from '@patternfly/react-core';
import { Card, CardHeader, CardActions, CardTitle, CardBody, Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, KebabToggle, } from '@patternfly/react-core';

class SelectableCard extends React.Component {
constructor(props) {
Expand All @@ -388,7 +388,7 @@ class SelectableCard extends React.Component {
this.setState({
selected: newSelected
})
};
};
this.onToggle = (isOpen, event) => {
event.stopPropagation()
this.setState({
Expand Down
14 changes: 11 additions & 3 deletions packages/react-integration/cypress/integration/card.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ describe('Card Demo Test', () => {
});

it('Verify card is flat', () => {
cy.get('article')
.last()
.should('have.class', 'pf-m-flat');
cy.get('#flatCard').should('have.class', 'pf-m-flat');
});

it('Verify that selectable card can be selected and unselected with keyboard input', () => {
cy.get('#selectableCard').focus();
cy.focused().should('have.class', 'pf-m-selectable');
cy.focused().should('not.have.class', 'pf-m-selected');
cy.focused().type('{enter}');
cy.focused().should('have.class', 'pf-m-selected');
cy.focused().type('{enter}');
cy.focused().should('not.have.class', 'pf-m-selected');
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import React from 'react';
import { Card, CardTitle, CardBody, CardFooter } from '@patternfly/react-core';
interface CardDemoState {
selected: string;
}

export class CardDemo extends React.Component {
static displayName = 'CardDemo';

state: CardDemoState = {
selected: null
};

onKeyDown = (event: any) => {
if (event.target !== event.currentTarget) {
return;
}
if ([13, 32].includes(event.keyCode)) {
const newSelected = event.currentTarget.id === this.state.selected ? null : event.currentTarget.id;
this.setState({
selected: newSelected
});
}
};

componentDidMount() {
window.scrollTo(0, 0);
}
Expand Down Expand Up @@ -36,7 +56,18 @@ export class CardDemo extends React.Component {
<CardFooter>Footer</CardFooter>
</Card>
<br></br>
<Card isFlat>
<Card id="flatCard" isFlat>
<CardTitle>Header</CardTitle>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
</Card>

<Card
id="selectableCard"
isSelectable
isSelected={this.state.selected === 'selectableCard'}
onKeyDown={this.onKeyDown}
>
<CardTitle>Header</CardTitle>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
Expand Down