Skip to content

Commit

Permalink
Updated example description and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Aug 23, 2023
1 parent af485c5 commit eceebd6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
4 changes: 3 additions & 1 deletion packages/react-core/src/components/Drawer/examples/Drawer.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ section: components

### With focus trap

Use the `focusTrap` property to enable and customize a focus trap on the `<DrawerPanelContent>`. Enabling a focus trap with `focusTrap.enabled` will also automatically place focus on the first focusable element when the drawer panel expands, and return focus to the previously focused element when it collapses.
When a [focus trap](/accessibility/product-development-guide#trapping-focus) is enabled on an element, a user will only be able to interact with the contents of that element until the focus trap is closed or deactivated.

To enable and customize a focus trap on a drawer panel, apply the `focusTrap` property to the `<DrawerPanelContent>` component. Enabling a focus trap with `focusTrap.enabled` will also automatically place focus on the first focusable element when the drawer panel expands, and return focus to the previously focused element when it collapses.

To customize which element receives focus when the drawer panel expands, use the `focusTrap.elementToFocusOnExpand` property.

Expand Down
59 changes: 36 additions & 23 deletions packages/react-integration/cypress/integration/drawer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,73 @@ describe('Drawer Demo Test', () => {
cy.visit('http://localhost:3000/drawer-demo-nav-link');
});

it('Verify focus is automatically handled with focus trap enabled', () => {
cy.get('#toggleFocusTrapButton').click();
cy.get('#focusTrap-panelContent .pf-v5-c-button.pf-m-plain').should('have.focus');
cy.get('#focusTrap-panelContent .pf-v5-c-button.pf-m-plain').click();
cy.get('#toggleFocusTrapButton').should('have.focus');
});

it('Verify focus can be customized with focus trap enabled', () => {
cy.get('#toggleCustomFocusButton').click();
// Wait for transition animation to end
cy.wait(500);
cy.get('#customFocus-panelContent').should('have.focus');
cy.get('#toggleCustomFocusButton').click();
});

it('Verify text in content', () => {
const drawerContent =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pretium est a porttitor vehicula. Quisque vel commodo urna. Morbi mattis rutrum ante, id vehicula ex accumsan ut. Morbi viverra, eros vel porttitor facilisis, eros purus aliquet erat,nec lobortis felis elit pulvinar sem. Vivamus vulputate, risus eget commodo eleifend, eros nibh porta quam, vitae lacinia leo libero at magna. Maecenas aliquam sagittis orci, et posuere nisi ultrices sit amet. Aliquam ex odio, malesuada sed posuere quis, pellentesque at mauris. Phasellus venenatis massa ex, eget pulvinar libero auctor pretium. Aliquam erat volutpat. Duis euismod justo in quam ullamcorper, in commodo massa vulputate.';

cy.get('.pf-v5-c-drawer').contains(drawerContent);
cy.get('#basic-drawer.pf-v5-c-drawer').contains(drawerContent);
});

it('Verify drawer expands and collapses', () => {
cy.get('.pf-v5-c-drawer').should('not.have.class', 'pf-m-expanded');
cy.get('#basic-drawer.pf-v5-c-drawer').should('not.have.class', 'pf-m-expanded');
cy.get('#toggleButton').click();
cy.get('.pf-v5-c-drawer').should('have.class', 'pf-m-expanded');
cy.get('#basic-drawer.pf-v5-c-drawer').should('have.class', 'pf-m-expanded');
cy.get('#toggleButton').click();
});

it('Verify bottom drawer with background variant', () => {
cy.get('.pf-v5-c-drawer').should('have.class', 'pf-m-panel-bottom');
cy.get('.pf-v5-c-drawer__panel').should('have.class', 'pf-m-light-200');
cy.get('#basic-drawer.pf-v5-c-drawer').should('have.class', 'pf-m-panel-bottom');
cy.get('#basic-drawer .pf-v5-c-drawer__panel').should('have.class', 'pf-m-light-200');
});

it('Verify panel widths', () => {
// Large viewport
const $drawerPanel = cy.get('.pf-v5-c-drawer__panel');
const $drawerPanel = cy.get('#basic-drawer .pf-v5-c-drawer__panel');
$drawerPanel.should('have.class', 'pf-m-width-100');
$drawerPanel.should('have.class', 'pf-m-width-50-on-lg');
$drawerPanel.should('have.class', 'pf-m-width-33-on-xl');
$drawerPanel.should('have.class', 'pf-m-width-25-on-2xl');
$drawerPanel.should('have.css', 'flex-basis', 'max(0% + 24px, min(0% + 300px, 100% + 0px))');
// Medium viewport
cy.viewport(800, 660);
cy.get('.pf-v5-c-drawer__panel').should('have.css', 'flex-basis', 'max(0% + 24px, min(100% + 0px, 100% + 0px))');
cy.get('#basic-drawer .pf-v5-c-drawer__panel').should(
'have.css',
'flex-basis',
'max(0% + 24px, min(100% + 0px, 100% + 0px))'
);
// Xl viewport
cy.viewport(1200, 660);
cy.get('.pf-v5-c-drawer__panel').should('have.css', 'flex-basis', 'max(0% + 24px, min(0% + 300px, 100% + 0px))');
cy.get('#basic-drawer .pf-v5-c-drawer__panel').should(
'have.css',
'flex-basis',
'max(0% + 24px, min(0% + 300px, 100% + 0px))'
);
// 2Xl viewport
cy.viewport(1450, 660);
cy.get('.pf-v5-c-drawer__panel').should('have.css', 'flex-basis', 'max(0% + 24px, min(0% + 300px, 100% + 0px))');
cy.get('#basic-drawer .pf-v5-c-drawer__panel').should(
'have.css',
'flex-basis',
'max(0% + 24px, min(0% + 300px, 100% + 0px))'
);
});

it('Verify that focus gets sent to drawer', () => {
cy.get('#toggleButton').click();
cy.wrap(() => cy.focused().contains('drawer-panel in demo with onExpand'), { timeout: 1000 });
});

it('Verify focus is automatically handled with focus trap enabled', () => {
cy.get('#toggleFocusTrapButton').click();
cy.get('#focusTrap-panelContent .pf-v5-c-button.pf-m-plain').should('have.focus');
cy.get('#focusTrap-panelContent .pf-v5-c-button.pf-m-plain').click();
cy.get('#toggleFocusTrapButton').should('have.focus');
});

it('Verify focus can be customized with focus trap enabled', () => {
cy.get('#toggleCustomFocusButton').click();
// Wait for transition animation to end
cy.wait(500);
cy.get('#customFocus-panelContent').should('have.focus');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class DrawerDemo extends React.Component<DrawerProps, DrawerDemoState> {
<Button id="toggleButton" onClick={this.onClick}>
Toggle Drawer
</Button>
<Drawer isExpanded={isExpanded} onExpand={this.onExpand} position="bottom">
<Drawer id="basic-drawer" isExpanded={isExpanded} onExpand={this.onExpand} position="bottom">
<DrawerSection colorVariant={DrawerColorVariant.default}>drawer-section</DrawerSection>
<DrawerContent colorVariant={DrawerColorVariant.default} panelContent={panelContent}>
<DrawerContentBody>{drawerContent}</DrawerContentBody>
Expand Down

0 comments on commit eceebd6

Please sign in to comment.