@instructure/ui-view 10.16.4-snapshot-4 → 10.16.4-snapshot-6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-view",
3
- "version": "10.16.4-snapshot-4",
3
+ "version": "10.16.4-snapshot-6",
4
4
  "description": "A component for basic styles including spacing, sizing, borders, display, positioning, and focus states.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,22 +24,22 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.26.0",
27
- "@instructure/console": "10.16.4-snapshot-4",
28
- "@instructure/emotion": "10.16.4-snapshot-4",
29
- "@instructure/shared-types": "10.16.4-snapshot-4",
30
- "@instructure/ui-color-utils": "10.16.4-snapshot-4",
31
- "@instructure/ui-dom-utils": "10.16.4-snapshot-4",
32
- "@instructure/ui-i18n": "10.16.4-snapshot-4",
33
- "@instructure/ui-position": "10.16.4-snapshot-4",
34
- "@instructure/ui-prop-types": "10.16.4-snapshot-4",
35
- "@instructure/ui-react-utils": "10.16.4-snapshot-4",
27
+ "@instructure/console": "10.16.4-snapshot-6",
28
+ "@instructure/emotion": "10.16.4-snapshot-6",
29
+ "@instructure/shared-types": "10.16.4-snapshot-6",
30
+ "@instructure/ui-color-utils": "10.16.4-snapshot-6",
31
+ "@instructure/ui-dom-utils": "10.16.4-snapshot-6",
32
+ "@instructure/ui-i18n": "10.16.4-snapshot-6",
33
+ "@instructure/ui-position": "10.16.4-snapshot-6",
34
+ "@instructure/ui-prop-types": "10.16.4-snapshot-6",
35
+ "@instructure/ui-react-utils": "10.16.4-snapshot-6",
36
36
  "prop-types": "^15.8.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@instructure/ui-axe-check": "10.16.4-snapshot-4",
40
- "@instructure/ui-babel-preset": "10.16.4-snapshot-4",
41
- "@instructure/ui-test-utils": "10.16.4-snapshot-4",
42
- "@instructure/ui-themes": "10.16.4-snapshot-4",
39
+ "@instructure/ui-axe-check": "10.16.4-snapshot-6",
40
+ "@instructure/ui-babel-preset": "10.16.4-snapshot-6",
41
+ "@instructure/ui-test-utils": "10.16.4-snapshot-6",
42
+ "@instructure/ui-themes": "10.16.4-snapshot-6",
43
43
  "@testing-library/jest-dom": "^6.6.3",
44
44
  "@testing-library/react": "^16.0.1",
45
45
  "vitest": "^2.1.8"
@@ -398,9 +398,6 @@ type: example
398
398
  `position` sets the CSS position rule for the component: `static`, `absolute`, `relative`,
399
399
  `sticky`, or `fixed`.
400
400
 
401
- > Note that `position="sticky"` is currently [not as fully supported](https://caniuse.com/#feat=css-sticky)
402
- > as the other values.
403
-
404
401
  ```js
405
402
  ---
406
403
  type: example
@@ -428,25 +425,19 @@ type: example
428
425
 
429
426
  By default, if a `View` is rendered as a focusable element, a focus outline will display when it is focused for accessibility.
430
427
 
431
- > Note that `position` must be set to `relative` for the focus ring to display.
432
- > (This restriction exists because the focus ring requires styling a pseudo element
433
- > that has absolute positioning.)
434
-
435
428
  ```javascript
436
429
  ---
437
430
  type: example
438
431
  ---
439
- <View
440
- position="relative"
441
- tabIndex="0"
442
- role="button"
443
- cursor="pointer"
444
- display="block"
445
- margin="large"
446
- padding="small"
447
- >
448
- Tab here to see the focus outline
449
- </View>
432
+ <Flex gap="medium" direction="column">
433
+ <View tabIndex="0" role="button" cursor="pointer">
434
+ Tab here to see the focus outline
435
+ </View>
436
+ <View focusWithin>
437
+ if the <code>focusWithin</code> prop is <code>true</code>, the View will display the focus ring if any of its descendants receives focus
438
+ <div tabindex="0" role="button" style={{outline: 'none'}}>Tab here to see the focus outline</div>
439
+ </View>
440
+ </Flex>
450
441
  ```
451
442
 
452
443
  In some situations, you may want to manually control when the focus outline is displayed instead of leaving it up to the browser.
@@ -455,8 +446,7 @@ Be careful when overriding the display of the focus outline as it is essential f
455
446
 
456
447
  The focus outline adjusts to account for the shape of the View. For example, the following values can be set for `borderRadius`:
457
448
  `circle`, `pill`, `small`, `medium`, and `large`. In each case, the border radius of the focus outline will automatically adjust
458
- to match the border radius of the corresponding View. For Views with irregular border radius (e.g., `borderRadius="small large none medium"`), the focus outline will appear with square edges. The color of the focus outline can be
459
- changed for different contexts via the `focusColor` property.
449
+ to match the border radius of the corresponding View. The color of the focus outline can be changed for different contexts via the `focusColor` property.
460
450
 
461
451
  - ```javascript
462
452
  class FocusedExample extends React.Component {
@@ -465,7 +455,8 @@ changed for different contexts via the `focusColor` property.
465
455
 
466
456
  this.state = {
467
457
  isFocused: true,
468
- inset: false
458
+ inset: false,
459
+ focusColor: undefined
469
460
  }
470
461
  }
471
462
 
@@ -477,6 +468,10 @@ changed for different contexts via the `focusColor` property.
477
468
  this.setState({ inset: event.target.checked })
478
469
  }
479
470
 
471
+ updateFocusRingColor = (event, value) => {
472
+ this.setState({ focusColor: value })
473
+ }
474
+
480
475
  render() {
481
476
  return (
482
477
  <View as="div">
@@ -495,16 +490,32 @@ changed for different contexts via the `focusColor` property.
495
490
  </ScreenReaderContent>
496
491
  }
497
492
  >
498
- <Checkbox
499
- label="withFocusOutline"
500
- checked={this.state.isFocused}
501
- onChange={this.updateFocused}
502
- />
503
- <Checkbox
504
- label="focusPosition = inset"
505
- checked={this.state.inset}
506
- onChange={this.updateInset}
507
- />
493
+ <Flex gap="small" direction="row">
494
+ <Flex gap="small" direction="column" width="15rem">
495
+ <Checkbox
496
+ label="withFocusOutline"
497
+ checked={this.state.isFocused}
498
+ onChange={this.updateFocused}
499
+ />
500
+ <Checkbox
501
+ label="focusPosition = inset"
502
+ checked={this.state.inset}
503
+ onChange={this.updateInset}
504
+ />
505
+ </Flex>
506
+ <RadioInputGroup
507
+ onChange={this.updateFocusRingColor}
508
+ name="focusColor"
509
+ defaultValue="info"
510
+ variant="toggle"
511
+ description="Focus ring color"
512
+ >
513
+ <RadioInput label="info" value="info" />
514
+ <RadioInput label="inverse" value="inverse" />
515
+ <RadioInput label="success" value="success" />
516
+ <RadioInput label="danger" value="danger" />
517
+ </RadioInputGroup>
518
+ </Flex>
508
519
  </FormFieldGroup>
509
520
  </View>
510
521
  <View as="div">
@@ -517,6 +528,7 @@ changed for different contexts via the `focusColor` property.
517
528
  borderRadius="small"
518
529
  borderWidth="small"
519
530
  position="relative"
531
+ focusColor={this.state.focusColor}
520
532
  withFocusOutline={this.state.isFocused}
521
533
  focusPosition={this.state.inset ? 'inset' : 'offset'}
522
534
  >
@@ -530,6 +542,7 @@ changed for different contexts via the `focusColor` property.
530
542
  borderRadius="medium"
531
543
  borderWidth="small"
532
544
  position="relative"
545
+ focusColor={this.state.focusColor}
533
546
  withFocusOutline={this.state.isFocused}
534
547
  focusPosition={this.state.inset ? 'inset' : 'offset'}
535
548
  >
@@ -543,6 +556,7 @@ changed for different contexts via the `focusColor` property.
543
556
  borderRadius="large"
544
557
  borderWidth="small"
545
558
  position="relative"
559
+ focusColor={this.state.focusColor}
546
560
  withFocusOutline={this.state.isFocused}
547
561
  focusPosition={this.state.inset ? 'inset' : 'offset'}
548
562
  >
@@ -557,6 +571,7 @@ changed for different contexts via the `focusColor` property.
557
571
  borderRadius="circle"
558
572
  borderWidth="small"
559
573
  position="relative"
574
+ focusColor={this.state.focusColor}
560
575
  withFocusOutline={this.state.isFocused}
561
576
  focusPosition={this.state.inset ? 'inset' : 'offset'}
562
577
  >
@@ -583,7 +598,7 @@ changed for different contexts via the `focusColor` property.
583
598
  borderWidth="small"
584
599
  position="relative"
585
600
  withFocusOutline={this.state.isFocused}
586
- focusColor="inverse"
601
+ focusColor={this.state.focusColor}
587
602
  focusPosition={this.state.inset ? 'inset' : 'offset'}
588
603
  >
589
604
  medium
@@ -597,9 +612,9 @@ changed for different contexts via the `focusColor` property.
597
612
  borderRadius="pill"
598
613
  borderWidth="small"
599
614
  position="relative"
600
- focusColor="success"
601
615
  width="100px"
602
616
  textAlign="center"
617
+ focusColor={this.state.focusColor}
603
618
  withFocusOutline={this.state.isFocused}
604
619
  focusPosition={this.state.inset ? 'inset' : 'offset'}
605
620
  >
@@ -612,8 +627,8 @@ changed for different contexts via the `focusColor` property.
612
627
  background="primary"
613
628
  borderWidth="small"
614
629
  borderRadius="none large"
615
- focusColor="danger"
616
630
  position="relative"
631
+ focusColor={this.state.focusColor}
617
632
  withFocusOutline={this.state.isFocused}
618
633
  focusPosition={this.state.inset ? 'inset' : 'offset'}
619
634
  >
@@ -624,7 +639,6 @@ changed for different contexts via the `focusColor` property.
624
639
  )
625
640
  }
626
641
  }
627
-
628
642
  render(<FocusedExample />)
629
643
  ```
630
644
 
@@ -632,9 +646,11 @@ changed for different contexts via the `focusColor` property.
632
646
  const FocusedExample = () => {
633
647
  const [isFocused, setIsFocused] = useState(true)
634
648
  const [inset, setInset] = useState(false)
649
+ const [focusColor, setfocusColor] = useState(undefined)
635
650
 
636
651
  const updateFocused = (event) => setIsFocused(event.target.checked)
637
652
  const updateInset = (event) => setInset(event.target.checked)
653
+ const updateFocusRingColor = (event) => setfocusColor(event.target.value)
638
654
 
639
655
  return (
640
656
  <View as="div">
@@ -653,16 +669,32 @@ changed for different contexts via the `focusColor` property.
653
669
  </ScreenReaderContent>
654
670
  }
655
671
  >
656
- <Checkbox
657
- label="withFocusOutline"
658
- checked={isFocused}
659
- onChange={updateFocused}
660
- />
661
- <Checkbox
662
- label="focusPosition = inset"
663
- checked={inset}
664
- onChange={updateInset}
665
- />
672
+ <Flex gap="small" direction="row">
673
+ <Flex gap="small" direction="column" width="15rem">
674
+ <Checkbox
675
+ label="withFocusOutline"
676
+ checked={isFocused}
677
+ onChange={updateFocused}
678
+ />
679
+ <Checkbox
680
+ label="focusPosition = inset"
681
+ checked={inset}
682
+ onChange={updateInset}
683
+ />
684
+ </Flex>
685
+ <RadioInputGroup
686
+ onChange={updateFocusRingColor}
687
+ name="focusColor_2"
688
+ defaultValue="info"
689
+ variant="toggle"
690
+ description="Focus ring color"
691
+ >
692
+ <RadioInput label="info" value="info" />
693
+ <RadioInput label="inverse" value="inverse" />
694
+ <RadioInput label="success" value="success" />
695
+ <RadioInput label="danger" value="danger" />
696
+ </RadioInputGroup>
697
+ </Flex>
666
698
  </FormFieldGroup>
667
699
  </View>
668
700
  <View as="div">
@@ -675,6 +707,7 @@ changed for different contexts via the `focusColor` property.
675
707
  borderRadius="small"
676
708
  borderWidth="small"
677
709
  position="relative"
710
+ focusColor={focusColor}
678
711
  withFocusOutline={isFocused}
679
712
  focusPosition={inset ? 'inset' : 'offset'}
680
713
  >
@@ -689,6 +722,7 @@ changed for different contexts via the `focusColor` property.
689
722
  borderWidth="small"
690
723
  position="relative"
691
724
  withFocusOutline={isFocused}
725
+ focusColor={focusColor}
692
726
  focusPosition={inset ? 'inset' : 'offset'}
693
727
  >
694
728
  medium
@@ -702,6 +736,7 @@ changed for different contexts via the `focusColor` property.
702
736
  borderWidth="small"
703
737
  position="relative"
704
738
  withFocusOutline={isFocused}
739
+ focusColor={focusColor}
705
740
  focusPosition={inset ? 'inset' : 'offset'}
706
741
  >
707
742
  large
@@ -716,6 +751,7 @@ changed for different contexts via the `focusColor` property.
716
751
  borderWidth="small"
717
752
  position="relative"
718
753
  withFocusOutline={isFocused}
754
+ focusColor={focusColor}
719
755
  focusPosition={inset ? 'inset' : 'offset'}
720
756
  >
721
757
  <Flex
@@ -741,6 +777,7 @@ changed for different contexts via the `focusColor` property.
741
777
  borderWidth="small"
742
778
  position="relative"
743
779
  withFocusOutline={isFocused}
780
+ focusColor={focusColor}
744
781
  focusColor="inverse"
745
782
  focusPosition={inset ? 'inset' : 'offset'}
746
783
  >
@@ -758,6 +795,7 @@ changed for different contexts via the `focusColor` property.
758
795
  focusColor="success"
759
796
  width="100px"
760
797
  textAlign="center"
798
+ focusColor={focusColor}
761
799
  withFocusOutline={isFocused}
762
800
  focusPosition={inset ? 'inset' : 'offset'}
763
801
  >
@@ -772,6 +810,7 @@ changed for different contexts via the `focusColor` property.
772
810
  borderRadius="none large"
773
811
  focusColor="danger"
774
812
  position="relative"
813
+ focusColor={focusColor}
775
814
  withFocusOutline={isFocused}
776
815
  focusPosition={inset ? 'inset' : 'offset'}
777
816
  >
@@ -936,7 +975,9 @@ props.
936
975
 
937
976
  ### Debugging
938
977
 
939
- Set the `withVisualDebug` prop to see the View's boundaries.
978
+ Set the `withVisualDebug` prop to see the View's boundaries. Use this only for debugging.
979
+
980
+ > This effect uses a CSS box-shadow, so the `shadow` prop will be overridden
940
981
 
941
982
  ```js
942
983
  ---
@@ -234,39 +234,6 @@ describe('<View />', () => {
234
234
  expect(newStyles.maxWidth).toEqual('200px')
235
235
  })
236
236
 
237
- describe('withFocusOutline', () => {
238
- it('should warn when withFocusOutline is true without position=relative', () => {
239
- render(
240
- <View withFocusOutline>
241
- <h1>View Content</h1>
242
- </View>
243
- )
244
- const expectedErrorMessage =
245
- 'Warning: [View] the focus outline will only show if the `position` prop is `relative`.'
246
-
247
- expect(consoleErrorMock).toHaveBeenCalledWith(
248
- expect.stringContaining(expectedErrorMessage),
249
- expect.any(String)
250
- )
251
- })
252
-
253
- it('should warn when withFocusOutline is `true`, display is set to `inline`, and focusPosition is set to `offset`', () => {
254
- render(
255
- <View withFocusOutline display="inline" focusPosition="offset">
256
- <h1>View Content</h1>
257
- </View>
258
- )
259
-
260
- const expectedErrorMessage =
261
- 'Warning: [View] when display is set to `inline` the focus outline will only show if `focusPosition` is set to `inset`.'
262
-
263
- expect(consoleErrorMock).toHaveBeenCalledWith(
264
- expect.stringContaining(expectedErrorMessage),
265
- expect.any(String)
266
- )
267
- })
268
- })
269
-
270
237
  it('should meet a11y standards', async () => {
271
238
  const { container } = render(<View>View Content</View>)
272
239
 
package/src/View/props.ts CHANGED
@@ -135,9 +135,9 @@ type ViewOwnProps = {
135
135
  */
136
136
  insetBlockEnd?: string
137
137
  /**
138
- * Manually control if the `View` should display a focus outline. When left undefined (which is the default)
139
- * the focus outline will display automatically if the `View` is focusable and receives focus.
140
- * Note: This props is applicable only when the position prop is set to relative.
138
+ * Manually control if the `View` should display a focus outline.<br/>
139
+ * When left `undefined` (which is the default) the focus outline will display
140
+ * automatically if the `View` is focusable and receives focus.
141
141
  */
142
142
  withFocusOutline?: boolean
143
143
  /**
@@ -207,6 +207,12 @@ type ViewOwnProps = {
207
207
  * For inset type, the given value is decreased by the sum of the focus ring' offset and the focus ring's width.
208
208
  */
209
209
  focusRingBorderRadius?: string
210
+ /**
211
+ * Display the focus ring when any of the descendants is focused.
212
+ * (uses the [:focus-within](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within)
213
+ * CSS selector)
214
+ */
215
+ focusWithin?: boolean
210
216
  }
211
217
 
212
218
  type PropKeys = keyof ViewOwnProps
@@ -280,7 +286,8 @@ const propTypes: PropValidators<PropKeys> = {
280
286
  withVisualDebug: PropTypes.bool,
281
287
  dir: PropTypes.oneOf(Object.values(textDirectionContextConsumer.DIRECTION)),
282
288
  overscrollBehavior: PropTypes.oneOf(['auto', 'contain', 'none']),
283
- focusRingBorderRadius: PropTypes.string
289
+ focusRingBorderRadius: PropTypes.string,
290
+ focusWithin: PropTypes.bool
284
291
  }
285
292
 
286
293
  // This variable will be attached as static property on the `View` component
@@ -321,7 +328,8 @@ const allowedProps: AllowedPropKeys = [
321
328
  'width',
322
329
  'withFocusOutline',
323
330
  'withVisualDebug',
324
- 'focusRingBorderRadius'
331
+ 'focusRingBorderRadius',
332
+ 'focusWithin'
325
333
  ]
326
334
 
327
335
  export { propTypes, allowedProps }