Skip to content

Support for matching pressed state of toggle buttons #203

Open
@bfintal

Description

@bfintal

Describe the feature you'd like:

Add a matcher for aria-pressed for checking button toggle states.

Suggested implementation:

A new matcher called toBePressed

Describe alternatives you've considered:

An alternative solution would be to check for the attribute aria-pressed="true" or aria-pressed="mixed"

Teachability, Documentation, Adoption, Migration Strategy:

Docs entry:


toBePressed

toBePressed()

This allows you to check if a form element is currently pressed.

An element is pressed if it is a button having a aria-pressed="true" or aria-pressed="mixed"
attribute.

Examples

<button data-testid="pressed-button" aria-pressed="true" />
<input data-testid="pressed-input" type="button" aria-pressed="true" />
<div data-testid="pressed-div" role="button" tabindex="0" aria-pressed="true" />
<button data-testid="pressed-button-mixed" aria-pressed="mixed" />
expect(getByTestId('pressed-button')).toBePressed()
expect(getByTestId('pressed-input')).toBePressed()
expect(getByTestId('pressed-div')).toBePressed()
expect(getByTestId('pressed-button-mixed')).toBePressed()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions