-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-card): add selectable prop
#23349
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
Changes from all commits
fa5b38e
359182d
e7f05d0
e3b082e
cd5a709
88f6706
20d4322
7b8a5d6
92e713f
f85bf7b
5851cc9
584d425
bf00233
98c98ee
f8b84eb
21a194a
44dace1
3e63168
3324522
27718c3
713b3d8
dab2b6b
641369d
bb62575
8af1b84
8736b91
9b0e88e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "feat: add card selection functionality", | ||
| "packageName": "@fluentui/react-card", | ||
| "email": "39736248+andrefcdias@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import type {} from '@cypress/react'; | |
| import { FluentProvider } from '@fluentui/react-provider'; | ||
| import { webLightTheme } from '@fluentui/react-theme'; | ||
| import { Button } from '@fluentui/react-button'; | ||
| import { checkboxClassNames } from '@fluentui/react-checkbox'; | ||
| import { Card, CardFooter, CardHeader } from '@fluentui/react-card'; | ||
| import type { CardProps } from '@fluentui/react-card'; | ||
|
|
||
|
|
@@ -12,7 +13,7 @@ const mountFluent = (element: JSX.Element) => { | |
| }; | ||
|
|
||
| const CardSample = (props: CardProps) => { | ||
| const ASSET_URL = 'https://raw.githubusercontent.com/microsoft/fluentui/master/packages/react-card'; | ||
| const ASSET_URL = 'https://raw.githubusercontent.com/microsoft/fluentui/master/packages/react-components/react-card'; | ||
|
|
||
| const powerpointLogoURL = ASSET_URL + '/assets/powerpoint_logo.svg'; | ||
|
|
||
|
|
@@ -32,10 +33,10 @@ const CardSample = (props: CardProps) => { | |
| plum. | ||
| </div> | ||
| <CardFooter> | ||
| <Button id="open-button" onClick={alert} appearance="primary"> | ||
| <Button id="open-button" onClick={() => console.log('open-button clicked')} appearance="primary"> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid usage of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wondering what is the best practice here ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that |
||
| Open | ||
| </Button> | ||
| <Button id="close-button" appearance="outline"> | ||
| <Button id="close-button" onClick={() => console.log('close-button clicked')} appearance="outline"> | ||
| Close | ||
| </Button> | ||
| </CardFooter> | ||
|
|
@@ -240,4 +241,116 @@ describe('Card', () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('selectable', () => { | ||
| it('should not be selectable by default', () => { | ||
| mountFluent(<CardSample />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('not.exist'); | ||
| }); | ||
|
|
||
| it('should show checkbox when selectable', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('exist').should('not.be.checked'); | ||
| }); | ||
|
|
||
| it('should select with a mouse click', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).realClick(); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should select with the Enter key', () => { | ||
theerebuss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).focus().realPress('Enter'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should select with the Space key', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).focus().realPress('Space'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should select with a mouse click anywhere on the card', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`#card`).realClick(); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should select with the Enter key anywhere on the card', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`#card`).focus().realPress('Enter'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should select with the Space key anywhere on the card', () => { | ||
| mountFluent(<CardSample selectable />); | ||
|
|
||
| cy.get(`#card`).focus().realPress('Space'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('focusable + selectable', () => { | ||
| it('should not select on click', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`#card`).realClick(); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('not.be.checked'); | ||
| }); | ||
|
|
||
| it('should not select on Enter key', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`#card`).focus().realPress('Enter'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('not.be.checked'); | ||
| }); | ||
|
|
||
| it('should not select on Space key', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`#card`).focus().realPress('Space'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('not.be.checked'); | ||
| }); | ||
|
|
||
| it('should select on checkbox click', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).realClick(); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
|
|
||
| it('should not select on checkbox Enter key press', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).focus().realPress('Enter'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('not.be.checked'); | ||
| }); | ||
|
|
||
| it('should select on checkbox Space key press', () => { | ||
| mountFluent(<CardSample focusMode="no-tab" selectable />); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).focus().realPress('Space'); | ||
|
|
||
| cy.get(`.${checkboxClassNames.input}`).should('be.checked'); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RTL not necessary, already tested in non-interactive test.