@instructure/ui-source-code-editor 10.11.1-snapshot-5 → 10.11.1-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/CHANGELOG.md CHANGED
@@ -3,9 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [10.11.1-snapshot-5](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.11.1-snapshot-5) (2025-02-10)
6
+ ## [10.11.1-snapshot-6](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.11.1-snapshot-6) (2025-02-11)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-source-code-editor
8
+
9
+ ### Bug Fixes
10
+
11
+ * **ui-sourcecodeeditor:** link label to input field programmatically ([b092b45](https://github.com/instructure/instructure-ui/commit/b092b457777c2dea480c09da87989cf985a1713e))
9
12
 
10
13
 
11
14
 
@@ -1,4 +1,4 @@
1
- var _SourceCodeEditor;
1
+ var _SourceCodeEditor, _SourceCodeEditor2;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -47,5 +47,17 @@ describe('<SourceCodeEditor />', () => {
47
47
  color: '#116644'
48
48
  });
49
49
  });
50
+ it('should link editor element to label using aria-labelledby attribute', async () => {
51
+ var _container$querySelec;
52
+ const _render2 = render(_SourceCodeEditor2 || (_SourceCodeEditor2 = /*#__PURE__*/React.createElement(SourceCodeEditor, {
53
+ label: "test",
54
+ language: "jsx",
55
+ defaultValue: "const a = 2;"
56
+ }))),
57
+ container = _render2.container;
58
+ const editorElement = container.querySelector('[role="textbox"]');
59
+ const labelId = (_container$querySelec = container.querySelector('[class$="-label"]')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.id;
60
+ expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
61
+ });
50
62
  });
51
63
  });
@@ -195,6 +195,14 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
195
195
  containerRef(el);
196
196
  }
197
197
  };
198
+ this.assignAriaLabel = () => {
199
+ if (this._containerRef) {
200
+ const editorDiv = this._containerRef.querySelector('[role="textbox"]');
201
+ if (editorDiv) {
202
+ editorDiv.setAttribute('aria-labelledby', `${this._id}`);
203
+ }
204
+ }
205
+ };
198
206
  this._id = props.deterministicId();
199
207
  }
200
208
  componentDidMount() {
@@ -219,6 +227,7 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
219
227
  if (indentOnLoad) {
220
228
  this.indentAll();
221
229
  }
230
+ this.assignAriaLabel();
222
231
  }
223
232
  componentWillUnmount() {
224
233
  var _this$_editorView5;
@@ -487,7 +496,7 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
487
496
  css: styles === null || styles === void 0 ? void 0 : styles.codeEditor
488
497
  }, passthroughProps(omitProps(restProps, SourceCodeEditor.allowedProps))), jsx("label", {
489
498
  css: styles === null || styles === void 0 ? void 0 : styles.label,
490
- htmlFor: this._id
499
+ id: this._id
491
500
  }, jsx(ScreenReaderContent, null, label), jsx("div", {
492
501
  ref: this.handleContainerRef,
493
502
  css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
@@ -5,7 +5,7 @@ var _react = _interopRequireDefault(require("react"));
5
5
  var _react2 = require("@testing-library/react");
6
6
  var _index = _interopRequireDefault(require("../index"));
7
7
  require("@testing-library/jest-dom");
8
- var _SourceCodeEditor;
8
+ var _SourceCodeEditor, _SourceCodeEditor2;
9
9
  /*
10
10
  * The MIT License (MIT)
11
11
  *
@@ -50,5 +50,17 @@ describe('<SourceCodeEditor />', () => {
50
50
  color: '#116644'
51
51
  });
52
52
  });
53
+ it('should link editor element to label using aria-labelledby attribute', async () => {
54
+ var _container$querySelec;
55
+ const _render2 = (0, _react2.render)(_SourceCodeEditor2 || (_SourceCodeEditor2 = /*#__PURE__*/_react.default.createElement(_index.default, {
56
+ label: "test",
57
+ language: "jsx",
58
+ defaultValue: "const a = 2;"
59
+ }))),
60
+ container = _render2.container;
61
+ const editorElement = container.querySelector('[role="textbox"]');
62
+ const labelId = (_container$querySelec = container.querySelector('[class$="-label"]')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.id;
63
+ expect(editorElement).toHaveAttribute('aria-labelledby', labelId);
64
+ });
53
65
  });
54
66
  });
@@ -202,6 +202,14 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
202
202
  containerRef(el);
203
203
  }
204
204
  };
205
+ this.assignAriaLabel = () => {
206
+ if (this._containerRef) {
207
+ const editorDiv = this._containerRef.querySelector('[role="textbox"]');
208
+ if (editorDiv) {
209
+ editorDiv.setAttribute('aria-labelledby', `${this._id}`);
210
+ }
211
+ }
212
+ };
205
213
  this._id = props.deterministicId();
206
214
  }
207
215
  componentDidMount() {
@@ -226,6 +234,7 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
226
234
  if (indentOnLoad) {
227
235
  this.indentAll();
228
236
  }
237
+ this.assignAriaLabel();
229
238
  }
230
239
  componentWillUnmount() {
231
240
  var _this$_editorView5;
@@ -494,7 +503,7 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
494
503
  css: styles === null || styles === void 0 ? void 0 : styles.codeEditor
495
504
  }, (0, _passthroughProps.passthroughProps)((0, _omitProps.omitProps)(restProps, SourceCodeEditor.allowedProps))), (0, _emotion.jsx)("label", {
496
505
  css: styles === null || styles === void 0 ? void 0 : styles.label,
497
- htmlFor: this._id
506
+ id: this._id
498
507
  }, (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, label), (0, _emotion.jsx)("div", {
499
508
  ref: this.handleContainerRef,
500
509
  css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-source-code-editor",
3
- "version": "10.11.1-snapshot-5",
3
+ "version": "10.11.1-snapshot-6",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "10.11.1-snapshot-5",
27
- "@instructure/ui-test-queries": "10.11.1-snapshot-5",
28
- "@instructure/ui-test-utils": "10.11.1-snapshot-5",
26
+ "@instructure/ui-babel-preset": "10.11.1-snapshot-6",
27
+ "@instructure/ui-test-queries": "10.11.1-snapshot-6",
28
+ "@instructure/ui-test-utils": "10.11.1-snapshot-6",
29
29
  "@testing-library/jest-dom": "^6.6.3",
30
30
  "@testing-library/react": "^16.0.1",
31
31
  "vitest": "^2.1.8"
@@ -45,20 +45,20 @@
45
45
  "@codemirror/search": "^6.5.6",
46
46
  "@codemirror/state": "^6.4.1",
47
47
  "@codemirror/view": "^6.34.1",
48
- "@instructure/emotion": "10.11.1-snapshot-5",
49
- "@instructure/shared-types": "10.11.1-snapshot-5",
50
- "@instructure/ui-a11y-content": "10.11.1-snapshot-5",
51
- "@instructure/ui-buttons": "10.11.1-snapshot-5",
52
- "@instructure/ui-dom-utils": "10.11.1-snapshot-5",
53
- "@instructure/ui-i18n": "10.11.1-snapshot-5",
54
- "@instructure/ui-icons": "10.11.1-snapshot-5",
55
- "@instructure/ui-prop-types": "10.11.1-snapshot-5",
56
- "@instructure/ui-react-utils": "10.11.1-snapshot-5",
57
- "@instructure/ui-test-locator": "10.11.1-snapshot-5",
58
- "@instructure/ui-testable": "10.11.1-snapshot-5",
59
- "@instructure/ui-text-input": "10.11.1-snapshot-5",
60
- "@instructure/ui-themes": "10.11.1-snapshot-5",
61
- "@instructure/ui-utils": "10.11.1-snapshot-5",
48
+ "@instructure/emotion": "10.11.1-snapshot-6",
49
+ "@instructure/shared-types": "10.11.1-snapshot-6",
50
+ "@instructure/ui-a11y-content": "10.11.1-snapshot-6",
51
+ "@instructure/ui-buttons": "10.11.1-snapshot-6",
52
+ "@instructure/ui-dom-utils": "10.11.1-snapshot-6",
53
+ "@instructure/ui-i18n": "10.11.1-snapshot-6",
54
+ "@instructure/ui-icons": "10.11.1-snapshot-6",
55
+ "@instructure/ui-prop-types": "10.11.1-snapshot-6",
56
+ "@instructure/ui-react-utils": "10.11.1-snapshot-6",
57
+ "@instructure/ui-test-locator": "10.11.1-snapshot-6",
58
+ "@instructure/ui-testable": "10.11.1-snapshot-6",
59
+ "@instructure/ui-text-input": "10.11.1-snapshot-6",
60
+ "@instructure/ui-themes": "10.11.1-snapshot-6",
61
+ "@instructure/ui-utils": "10.11.1-snapshot-6",
62
62
  "@lezer/highlight": "1.2.1",
63
63
  "prop-types": "^15.8.1"
64
64
  },
@@ -231,7 +231,7 @@ class LanguageExamples extends React.Component {
231
231
  <Flex.Item padding="0 0 0 large" shouldGrow shouldShrink>
232
232
  <FormField label="SourceCodeEditor with syntax highlight">
233
233
  <SourceCodeEditor
234
- label={`${this.state.currentLanguage} code editor`}
234
+ label={`${this.state.currentLanguage} SourceCodeEditor with syntax highlight`}
235
235
  language={this.state.currentLanguage}
236
236
  value={this.state.currentValue}
237
237
  onChange={(value) => {
@@ -44,5 +44,19 @@ describe('<SourceCodeEditor />', () => {
44
44
  expect(activeLine[1]).toHaveStyle({ color: '#0000ff' })
45
45
  expect(activeLine[2]).toHaveStyle({ color: '#116644' })
46
46
  })
47
+
48
+ it('should link editor element to label using aria-labelledby attribute', async () => {
49
+ const { container } = render(
50
+ <SourceCodeEditor
51
+ label="test"
52
+ language="jsx"
53
+ defaultValue="const a = 2;"
54
+ />
55
+ )
56
+ const editorElement = container.querySelector('[role="textbox"]')
57
+ const labelId = container.querySelector('[class$="-label"]')?.id
58
+
59
+ expect(editorElement).toHaveAttribute('aria-labelledby', labelId)
60
+ })
47
61
  })
48
62
  })
@@ -302,6 +302,7 @@ class SourceCodeEditor extends Component<SourceCodeEditorProps> {
302
302
  if (indentOnLoad) {
303
303
  this.indentAll()
304
304
  }
305
+ this.assignAriaLabel()
305
306
  }
306
307
 
307
308
  componentWillUnmount() {
@@ -644,6 +645,15 @@ class SourceCodeEditor extends Component<SourceCodeEditorProps> {
644
645
  }
645
646
  }
646
647
 
648
+ assignAriaLabel = () => {
649
+ if (this._containerRef) {
650
+ const editorDiv = this._containerRef.querySelector('[role="textbox"]')
651
+ if (editorDiv) {
652
+ editorDiv.setAttribute('aria-labelledby', `${this._id}`)
653
+ }
654
+ }
655
+ }
656
+
647
657
  render() {
648
658
  const { label, styles, ...restProps } = this.props
649
659
 
@@ -655,7 +665,7 @@ class SourceCodeEditor extends Component<SourceCodeEditorProps> {
655
665
  omitProps(restProps, SourceCodeEditor.allowedProps)
656
666
  )}
657
667
  >
658
- <label css={styles?.label} htmlFor={this._id}>
668
+ <label css={styles?.label} id={this._id}>
659
669
  <ScreenReaderContent>{label}</ScreenReaderContent>
660
670
  <div
661
671
  ref={this.handleContainerRef}