-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Input: fix issues from a11y review #21205
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Fix styling issues found in accessibility review", | ||
"packageName": "@fluentui/react-input", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,11 @@ const useRootStyles = makeStyles({ | |
// This is if the user clicks the field again while it's already focused | ||
borderBottomColor: tokens.colorCompoundBrandStrokePressed, | ||
}, | ||
':focus-within': { | ||
outlineWidth: '2px', | ||
outlineStyle: 'solid', | ||
outlineColor: 'transparent', | ||
}, | ||
}, | ||
small: { | ||
minHeight: fieldHeights.small, | ||
|
@@ -167,15 +172,20 @@ const useRootStyles = makeStyles({ | |
}, | ||
disabled: { | ||
cursor: 'not-allowed', | ||
backgroundColor: tokens.colorTransparentBackground, | ||
...shorthands.border('1px', 'solid', tokens.colorNeutralStrokeDisabled), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), // because underline doesn't usually have a radius | ||
'@media (forced-colors: active)': { | ||
...shorthands.borderColor('GrayText'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opinion: I wish the theme would handle this for us rather than having to ensure media queries in every disabled state for every component. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smhigley should confirm but IIRC this would only be needed when we're not using semantic elements (in this case, the wrapper div is visually pretending to be the input) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But yeah, I agree that it would be nicer to have this done automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it's only for when disabled colors are needed on non-semantic elements, or when we aren't using the native |
||
}, | ||
}, | ||
}); | ||
|
||
const useInputElementStyles = makeStyles({ | ||
base: { | ||
boxSizing: 'border-box', | ||
flexGrow: 1, | ||
minWidth: 0, // required to make the input shrink to fit the wrapper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about setting flexShrink? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It defaults to 1 (the desired value) but for some reason having a minWidth is also required to make it apply properly 🤷♀️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's b/c it appears there's some browser default for minWidth on text-like inputs that isn't exposed (you can verify by making a block input with no other styles, and shrinking the browser width down far enough) |
||
...shorthands.borderStyle('none'), // input itself never has a border (this is handled by inputWrapper) | ||
...shorthands.padding('0', horizontalSpacing.xxs), | ||
color: tokens.colorNeutralForeground1, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import * as React from 'react'; | ||
import { Label } from '@fluentui/react-label'; | ||
import { useId } from '@fluentui/react-utilities'; | ||
import { makeStyles } from '@fluentui/react-make-styles'; | ||
import { makeStyles, shorthands } from '@fluentui/react-make-styles'; | ||
import { tokens } from '@fluentui/react-theme'; | ||
import { Input } from '../index'; | ||
|
||
const useStyles = makeStyles({ | ||
root: { | ||
'& label': { display: 'block', paddingBottom: '2px' }, | ||
'& label:not(:first-child)': { paddingTop: '20px' }, | ||
// filledLighter and filledDarker appearances depend on particular background colors, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Should this comment be above the filledDarker and filledLighter lines rather than the padding of divs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily--these wrapper divs are used in all cases but only have a background color defined for filled appearances |
||
// so the story includes wrapper divs around the example of each appearance | ||
'> div': { ...shorthands.padding('20px'), ...shorthands.borderRadius('20px') }, | ||
'> div:not(:first-child)': { paddingTop: '10px' }, | ||
}, | ||
filledDarker: { backgroundColor: tokens.colorNeutralBackground1 }, | ||
// ideally should match doc site, #faf9f8 | ||
filledLighter: { backgroundColor: tokens.colorNeutralBackground2 }, | ||
}); | ||
|
||
export const Appearance = () => { | ||
|
@@ -20,17 +27,25 @@ export const Appearance = () => { | |
|
||
return ( | ||
<div className={styles.root}> | ||
<Label htmlFor={outlineId}>Outline (default)</Label> | ||
<Input appearance="outline" id={outlineId} placeholder="placeholder" /> | ||
<div> | ||
<Label htmlFor={outlineId}>Outline (default)</Label> | ||
<Input appearance="outline" id={outlineId} /> | ||
</div> | ||
|
||
<Label htmlFor={underlineId}>Underline</Label> | ||
<Input appearance="underline" id={underlineId} placeholder="placeholder" /> | ||
<div> | ||
<Label htmlFor={underlineId}>Underline</Label> | ||
<Input appearance="underline" id={underlineId} /> | ||
</div> | ||
|
||
<Label htmlFor={filledLighterId}>Filled lighter</Label> | ||
<Input appearance="filledLighter" id={filledLighterId} placeholder="placeholder" /> | ||
<div className={styles.filledLighter}> | ||
<Label htmlFor={filledLighterId}>Filled lighter</Label> | ||
<Input appearance="filledLighter" id={filledLighterId} /> | ||
</div> | ||
|
||
<Label htmlFor={filledDarkerId}>Filled darker</Label> | ||
<Input appearance="filledDarker" id={filledDarkerId} placeholder="placeholder" /> | ||
<div className={styles.filledDarker}> | ||
<Label htmlFor={filledDarkerId}>Filled darker</Label> | ||
<Input appearance="filledDarker" id={filledDarkerId} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
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.
Makes me wonder if we'll need a shorthand method for outline
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.
Filed #21231 -- I agree we should have a shorthand and thought about adding it in this PR, but figured it would be better to do separately in case it gets hung up on discussion for some reason (also I wasn't totally clear on how to set up the types from looking at other examples).