Carbon: Focus on wrong button in modal

Created on 24 Mar 2020  路  5Comments  路  Source: carbon-design-system/carbon

The cancel button is focused in modal instead of primary button

What package(s) are you using?

  • [ ] carbon-components
  • [X ] carbon-components-react

Detailed description

When a modal component is opened the close button (X) is focused instead of the primary button.

Is this issue related to a specific component?

This is related to the Modal component

What did you expect to happen? What happened instead? What would you like to
see changed?

Focus should be on the primary button.

What browser are you working in?

Chrome

What version of the Carbon Design System are you using?

Carbon X

Steps to reproduce the issue

This can also be seen in the story book:
https://react.carbondesignsystem.com/?path=/story/modal--default

Additional information

There are two references to this.button in the code (Module.js). That seems to cause the error.
One is https://github.com/carbon-design-system/carbon/blob/v10.10.0/packages/react/src/components/Modal/Modal.js#L346, another is https://github.com/carbon-design-system/carbon/blob/v10.10.0/packages/react/src/components/Modal/Modal.js#L411.
The code seems to have been originated from carbon-design-system/carbon-components-react#980.

image

modal bug 馃悰

Most helpful comment

While I would prefer better support for this in Modal, you should be able to set the selectorPrimaryFocus to ['.bx-btn-primary','.bx-btn-danger'].

All 5 comments

Note that when the primary button is actually a danger button, I'd expect the secondary button to be the default focus.

the behavior was changed to focus on the close/cancel button in https://github.com/carbon-design-system/carbon-components-react/pull/2096

you can change the primary focus target with the selectorPrimaryFocus prop

@emyarod How can I use the selectorPrimaryFocus on the primaryButton, when I use standard component _Module_ and the class of this button can be either .bx鈥攂tn鈥攑rimary or .bx鈥攂tn鈥攄anger?

While I would prefer better support for this in Modal, you should be able to set the selectorPrimaryFocus to ['.bx-btn-primary','.bx-btn-danger'].

@miriam-g as @renmaddox mentions you can set selectorPrimaryFocus to the CSS selector of the element you want to focus

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ConradSchmidt picture ConradSchmidt  路  3Comments

PatrickDuncan picture PatrickDuncan  路  3Comments

xrissot-ibm picture xrissot-ibm  路  3Comments

laurenmrice picture laurenmrice  路  3Comments

JordanWSmith15 picture JordanWSmith15  路  3Comments