-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[ButtonUnstyled] Allow receiving focus when disabled #32090
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a8703ae
[ButtonUnstyled] Allow receiving focus when disabled
michaldudak ab0efae
docs:api
michaldudak 739c594
Merge branch 'master' into button-disabled-focus
michaldudak 2c5ea74
Correct attributes in ButtonUnstyled
michaldudak 9077a5b
Add docs for the new prop
michaldudak e1757b5
Test tabindex on customized root
michaldudak ca6a677
Add further explanation about the prop
michaldudak f3d817f
Rename the prop
michaldudak 2592107
Update docs/data/base/components/button/button.md
michaldudak 0224b5b
Restart CI
michaldudak fab9861
docs:typescript
michaldudak 02af6d7
Merge remote-tracking branch 'upstream/master' into button-disabled-f…
michaldudak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
docs/data/base/components/button/UnstyledButtonsDisabledFocus.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import ButtonUnstyled, { buttonUnstyledClasses } from '@mui/base/ButtonUnstyled'; | ||
import { styled } from '@mui/system'; | ||
|
||
const blue = { | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
700: '#0059B2', | ||
}; | ||
|
||
const CustomButton = styled(ButtonUnstyled)` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-weight: bold; | ||
font-size: 0.875rem; | ||
background-color: ${blue[500]}; | ||
padding: 12px 24px; | ||
border-radius: 8px; | ||
color: white; | ||
transition: all 150ms ease; | ||
cursor: pointer; | ||
border: none; | ||
|
||
&:hover { | ||
background-color: ${blue[600]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.active} { | ||
background-color: ${blue[700]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.focusVisible} { | ||
box-shadow: 0 4px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 5px rgba(0, 127, 255, 0.5); | ||
outline: none; | ||
} | ||
|
||
&.${buttonUnstyledClasses.disabled} { | ||
opacity: 0.5; | ||
cursor: not-allowed; | ||
} | ||
`; | ||
|
||
export default function UnstyledButtonsDisabledFocus() { | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<CustomButton disabled>allowFocusWhenDisabled = false</CustomButton> | ||
<CustomButton disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> | ||
</Stack> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
docs/data/base/components/button/UnstyledButtonsDisabledFocus.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import ButtonUnstyled, { buttonUnstyledClasses } from '@mui/base/ButtonUnstyled'; | ||
import { styled } from '@mui/system'; | ||
|
||
const blue = { | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
700: '#0059B2', | ||
}; | ||
|
||
const CustomButton = styled(ButtonUnstyled)` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-weight: bold; | ||
font-size: 0.875rem; | ||
background-color: ${blue[500]}; | ||
padding: 12px 24px; | ||
border-radius: 8px; | ||
color: white; | ||
transition: all 150ms ease; | ||
cursor: pointer; | ||
border: none; | ||
|
||
&:hover { | ||
background-color: ${blue[600]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.active} { | ||
background-color: ${blue[700]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.focusVisible} { | ||
box-shadow: 0 4px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 5px rgba(0, 127, 255, 0.5); | ||
outline: none; | ||
} | ||
|
||
&.${buttonUnstyledClasses.disabled} { | ||
opacity: 0.5; | ||
cursor: not-allowed; | ||
} | ||
`; | ||
|
||
export default function UnstyledButtonsDisabledFocus() { | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<CustomButton disabled>allowFocusWhenDisabled = false</CustomButton> | ||
<CustomButton disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> | ||
</Stack> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
docs/data/base/components/button/UnstyledButtonsDisabledFocus.tsx.preview
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<CustomButton disabled>allowFocusWhenDisabled = false</CustomButton> | ||
<CustomButton disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> |
54 changes: 54 additions & 0 deletions
54
docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import ButtonUnstyled, { buttonUnstyledClasses } from '@mui/base/ButtonUnstyled'; | ||
import { styled } from '@mui/system'; | ||
|
||
const blue = { | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
700: '#0059B2', | ||
}; | ||
|
||
const CustomButton = styled(ButtonUnstyled)` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-weight: bold; | ||
font-size: 0.875rem; | ||
background-color: ${blue[500]}; | ||
padding: 12px 24px; | ||
border-radius: 8px; | ||
color: white; | ||
transition: all 150ms ease; | ||
cursor: pointer; | ||
border: none; | ||
|
||
&:hover:not(.${buttonUnstyledClasses.disabled}) { | ||
background-color: ${blue[600]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.active} { | ||
background-color: ${blue[700]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.focusVisible} { | ||
box-shadow: 0 4px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 5px rgba(0, 127, 255, 0.5); | ||
outline: none; | ||
} | ||
|
||
&.${buttonUnstyledClasses.disabled} { | ||
opacity: 0.5; | ||
cursor: not-allowed; | ||
} | ||
`; | ||
|
||
export default function UnstyledButtonsDisabledFocusCustom() { | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<CustomButton component="span" disabled> | ||
allowFocusWhenDisabled = false | ||
</CustomButton> | ||
<CustomButton component="span" disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> | ||
</Stack> | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import ButtonUnstyled, { buttonUnstyledClasses } from '@mui/base/ButtonUnstyled'; | ||
import { styled } from '@mui/system'; | ||
|
||
const blue = { | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
700: '#0059B2', | ||
}; | ||
|
||
const CustomButton = styled(ButtonUnstyled)` | ||
font-family: IBM Plex Sans, sans-serif; | ||
font-weight: bold; | ||
font-size: 0.875rem; | ||
background-color: ${blue[500]}; | ||
padding: 12px 24px; | ||
border-radius: 8px; | ||
color: white; | ||
transition: all 150ms ease; | ||
cursor: pointer; | ||
border: none; | ||
|
||
&:hover:not(.${buttonUnstyledClasses.disabled}) { | ||
background-color: ${blue[600]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.active} { | ||
background-color: ${blue[700]}; | ||
} | ||
|
||
&.${buttonUnstyledClasses.focusVisible} { | ||
box-shadow: 0 4px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 5px rgba(0, 127, 255, 0.5); | ||
outline: none; | ||
} | ||
|
||
&.${buttonUnstyledClasses.disabled} { | ||
opacity: 0.5; | ||
cursor: not-allowed; | ||
} | ||
`; | ||
|
||
export default function UnstyledButtonsDisabledFocusCustom() { | ||
return ( | ||
<Stack spacing={2} direction="row"> | ||
<CustomButton component="span" disabled> | ||
allowFocusWhenDisabled = false | ||
</CustomButton> | ||
<CustomButton component="span" disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> | ||
</Stack> | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.tsx.preview
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<CustomButton component="span" disabled> | ||
allowFocusWhenDisabled = false | ||
</CustomButton> | ||
<CustomButton component="span" disabled allowFocusWhenDisabled> | ||
allowFocusWhenDisabled = true | ||
</CustomButton> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe expand on when this would be a good use-cases (for example
MenuItem
) and why. For example, in some cases, disabled elements that are required for completing a step (or are just generally too important to be missed) should be focusable with TAB key.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I explained how this may be important for accessibility and shared that we use this internally for the menu button. Does it look better for you now?