File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
packages/ui-form-field/src Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import { runAxeCheck } from '@instructure/ui-axe-check'
2929import '@testing-library/jest-dom'
3030
3131import { FormField } from '../index'
32+ import { userEvent } from '@testing-library/user-event'
3233
3334describe ( '<FormField />' , ( ) => {
3435 let consoleWarningMock : ReturnType < typeof vi . spyOn >
@@ -65,9 +66,22 @@ describe('<FormField />', () => {
6566
6667 it ( 'should meet a11y standards' , async ( ) => {
6768 const { container } = render ( < FormField label = "foo" id = "bar" /> )
68-
6969 const axeCheck = await runAxeCheck ( container )
70-
7170 expect ( axeCheck ) . toBe ( true )
7271 } )
72+
73+ it ( 'should focus the control with the supplied id' , async ( ) => {
74+ const user = userEvent . setup ( )
75+ render (
76+ < FormField label = "labelText" id = "foo" >
77+ < input />
78+ < input id = "foo" />
79+ < input />
80+ </ FormField >
81+ )
82+ const label = screen . getByText ( 'labelText' ) . closest ( 'label' ) !
83+ await user . click ( label )
84+ const input = document . getElementById ( 'foo' ) !
85+ expect ( input ) . toHaveFocus ( )
86+ } )
7387} )
Original file line number Diff line number Diff line change @@ -68,6 +68,9 @@ class FormField extends Component<FormFieldProps> {
6868 label = { this . props . label }
6969 vAlign = { this . props . vAlign }
7070 as = "label"
71+ // This makes the control in focus when the label is clicked
72+ // This is needed to prevent the wrong element to be focused, e.g.
73+ // multi selects Tag-s
7174 htmlFor = { this . props . id }
7275 elementRef = { this . handleRef }
7376 margin = { this . props . margin }
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ const generateStyle = (
107107 // when inline add a small padding between the label and the control
108108 paddingRight : componentTheme . inlinePadding ,
109109 // and use the horizontal alignment prop
110- [ `@media screen and (min- width: ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
110+ [ `@media screen and (width >= ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
111111 {
112112 textAlign : labelAlign
113113 }
@@ -138,7 +138,7 @@ const generateStyle = (
138138 verticalAlign : 'middle' , // removes margin in inline layouts
139139 gridTemplateColumns : gridTemplateColumns ,
140140 gridTemplateAreas : gridTemplateAreas ,
141- [ `@media screen and (max- width: ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
141+ [ `@media screen and (width < ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
142142 {
143143 // for small screens use the stacked layout
144144 gridTemplateColumns : '100%' ,
@@ -171,7 +171,7 @@ const generateStyle = (
171171 ...( hasMessages && hasNewErrorMsgAndIsGroup && { marginTop : '0.375rem' } ) ,
172172 ...( isInlineLayout &&
173173 inline && {
174- [ `@media screen and (min- width: ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
174+ [ `@media screen and (width >= ${ componentTheme . stackedOrInlineBreakpoint } )` ] :
175175 {
176176 justifySelf : 'start'
177177 }
You can’t perform that action at this time.
0 commit comments