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

[BUG-7463] Response example tabs a11y #7464

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
84 changes: 52 additions & 32 deletions src/core/components/model-example.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import cx from "classnames"

export default class ModelExample extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -31,11 +32,11 @@ export default class ModelExample extends React.Component {
}

this.state = {
activeTab: activeTab
activeTab,
}
}

activeTab =( e ) => {
activeTab = ( e ) => {
let { target : { dataset : { name } } } = e

this.setState({
Expand All @@ -61,39 +62,58 @@ export default class ModelExample extends React.Component {

let isOAS3 = specSelectors.isOAS3()

return <div className="model-example">
<ul className="tab">
<li className={ "tabitem" + ( this.state.activeTab === "example" ? " active" : "") }>
<a className="tablinks" data-name="example" onClick={ this.activeTab }>{isExecute ? "Edit Value" : "Example Value"}</a>
</li>
{ schema ? <li className={ "tabitem" + ( this.state.activeTab === "model" ? " active" : "") }>
<a className={ "tablinks" + ( isExecute ? " inactive" : "" )} data-name="model" onClick={ this.activeTab }>
{isOAS3 ? "Schema" : "Model" }
</a>
</li> : null }
</ul>
<div>
{
this.state.activeTab === "example" ? (
example ? example : (
return (
<div className="model-example">
<ul className="tab" role="tablist">
<li className={cx("tabitem", { "active": this.state.activeTab === "example" })} role="presentation">
char0n marked this conversation as resolved.
Show resolved Hide resolved
char0n marked this conversation as resolved.
Show resolved Hide resolved
<button
char0n marked this conversation as resolved.
Show resolved Hide resolved
aria-selected={this.state.activeTab === "example"}
className="tablinks"
data-name="example"
onClick={ this.activeTab }
role="tab"
>
{isExecute ? "Edit Value" : "Example Value"}
</button>
</li>
{ schema && (
<li className={cx("tabitem", { "active": ["model", "schema"].includes(this.state.activeTab) })} role="presentation">
3ptmonster marked this conversation as resolved.
Show resolved Hide resolved
<button
aria-selected={["model", "schema"].includes(this.state.activeTab)}
char0n marked this conversation as resolved.
Show resolved Hide resolved
className={ "tablinks" + ( isExecute ? " inactive" : "" )}
3ptmonster marked this conversation as resolved.
Show resolved Hide resolved
data-name={isOAS3 ? "schema" : "model" }
onClick={ this.activeTab }
role="tab"
>
{isOAS3 ? "Schema" : "Model" }
</button>
</li>
)}
</ul>
{this.state.activeTab === "example" && (
<div data-name="examplePanel" role="tabpanel" aria-hidden={this.state.activeTab !== "example"} tabIndex="0">
char0n marked this conversation as resolved.
Show resolved Hide resolved
{example ? example : (
<HighlightCode value="(no example available)" getConfigs={ getConfigs } />
)
) : null
}
{
this.state.activeTab === "model" && <ModelWrapper schema={ schema }
getComponent={ getComponent }
getConfigs={ getConfigs }
specSelectors={ specSelectors }
expandDepth={ defaultModelExpandDepth }
specPath={specPath}
includeReadOnly = {includeReadOnly}
includeWriteOnly = {includeWriteOnly}/>
)}
</div>
)}


}
{["model", "schema"].includes(this.state.activeTab) && (
<div data-name={isOAS3 ? "schemaPanel" : "modelPanel" } role="tabpanel" aria-hidden={this.state.activeTab === "example"} tabIndex="0">
char0n marked this conversation as resolved.
Show resolved Hide resolved
<ModelWrapper
schema={ schema }
getComponent={ getComponent }
getConfigs={ getConfigs }
specSelectors={ specSelectors }
expandDepth={ defaultModelExpandDepth }
specPath={specPath}
includeReadOnly = {includeReadOnly}
includeWriteOnly = {includeWriteOnly}
/>
</div>
)}
</div>
</div>
)
}

}
35 changes: 35 additions & 0 deletions test/e2e-cypress/tests/a11y/7463.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe("Issue-7463: Response tab elements", () => {
char0n marked this conversation as resolved.
Show resolved Hide resolved
char0n marked this conversation as resolved.
Show resolved Hide resolved
describe("ModelExample within Operation", () => {
it("should render Example tabpanel by default", () => {
cy
.visit("/?url=/documents/petstore-expanded.openapi.yaml")
.get("#operations-default-addPet")
.click()
.get("div[data-name=examplePanel]")
.first()
.should("have.attr", "aria-hidden", "false")
})
it("should click Schema tab button and render Schema tabpanel for OpenAPI 3", () => {
cy
.visit("/?url=/documents/petstore-expanded.openapi.yaml")
.get("#operations-default-addPet")
.click()
.get("button.tablinks[data-name=schema]")
.first()
.click()
.get("div[data-name=schemaPanel]")
.first()
.should("have.attr", "aria-hidden", "false")
})
it("should click Model tab button and render Model tabpanel for OpenAPI 2", () => {
cy
.visit("/?url=/documents/petstore.swagger.yaml")
.get("#operations-pet-addPet")
.click()
.get("button.tablinks[data-name=model]")
.click()
.get("div[data-name=modelPanel]")
.should("have.attr", "aria-hidden", "false")
})
})
})
4 changes: 2 additions & 2 deletions test/e2e-cypress/tests/bugs/swos-63.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("SWOS-63: Schema/Model labeling", () => {
.visit("/?url=/documents/petstore-expanded.openapi.yaml")
.get("#operations-default-findPets")
.click()
.get("a.tablinks[data-name=model]")
.get("button.tablinks[data-name=schema]")
.contains("Schema")
})
it("should render `Models` for OpenAPI 2", () => {
Expand All @@ -28,7 +28,7 @@ describe("SWOS-63: Schema/Model labeling", () => {
.get("section.models > h4")
.get("#operations-pet-addPet")
.click()
.get("a.tablinks[data-name=model]")
.get("button.tablinks[data-name=model]")
.contains("Model")
})
})
Expand Down