FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(button): support setting tab index unless not button and disabled by boaz0 · Pull Request #3240 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) .tsx  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Button.test.tsx
      • Button.tsx
        • button.spec.ts
        • ButtonDemo.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ test('aria-disabled is set to true and tabIndex to -1 if component is not a butt
);
expect(view).toMatchSnapshot();
});

test('setting tab index through props', () => {
const view = mount(<Button tabIndex={0} >TabIndex 0 Button</Button>)
console.log(view.find('button').debug())
expect(view.find('button').props().tabIndex).toBe(0)
})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface ButtonProps extends React.HTMLProps<HTMLButtonElement> {
'aria-label'?: string;
/** Icon for the button if variant is a link */
icon?: React.ReactNode | null;
/** Set button tab index unless component is not a button and is disabled */
tabIndex?: number;
}

const Button: React.FunctionComponent<ButtonProps & InjectedOuiaProps> = ({
Expand All @@ -64,6 +66,7 @@ const Button: React.FunctionComponent<ButtonProps & InjectedOuiaProps> = ({
icon = null,
ouiaContext = null,
ouiaId = null,
tabIndex = null as number,
...props
}: ButtonProps & InjectedOuiaProps) => {
const Component = component as any;
Expand All @@ -85,7 +88,7 @@ const Button: React.FunctionComponent<ButtonProps & InjectedOuiaProps> = ({
className
)}
disabled={isButtonElement ? isDisabled : null}
tabIndex={isDisabled && !isButtonElement ? -1 : null}
tabIndex={isDisabled && !isButtonElement ? -1 : tabIndex}
type={isButtonElement ? type : null}
{...(ouiaContext.isOuia && {
'data-ouia-component-type': 'Button',
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ describe('Button Demo Test', () => {
});

it('Tertiary button should be disabled', () => {
cy.get('.pf-m-tertiary').should('have.class', 'pf-m-disabled');
cy.get('.pf-m-tertiary').should('be.disabled');
});

it('Verify primary button clicks', () => {
cy.get('.pf-m-primary').click();
cy.get('button.pf-m-primary').click();
cy.url().should('not.eq', 'http://localhost:3000/button-demo-nav-link');
});

it('Link button should be set to tabindex=-1', () => {
cy.get('.pf-m-link').should('have.attr', 'tabindex', '-1');
});
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class ButtonDemo extends React.Component {
>
Control Button
</Button>
<Button variant="link" tabIndex={-1}>
Button with tab index set to zero
</Button>
</React.Fragment>
);
}
Expand Down

Back | FazBrowse Home | New Git URL