@atlaskit/code 17.1.2 → 17.2.1

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
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/code
2
2
 
3
+ ## 17.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 17.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#153642](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/153642)
14
+ [`dca85557e83b9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dca85557e83b9) -
15
+ Adds a label prop for when code block is scrollable. Fixes the code block scrollablity bug.
16
+
3
17
  ## 17.1.2
4
18
 
5
19
  ### Patch Changes
@@ -12,8 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  var React = _react;
13
13
  var _runtime = require("@compiled/react/runtime");
14
14
  var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
15
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
16
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
16
  var decoration = {
18
17
  root: "_kqswh2mm _szpl2smr _dsq41wug _1xyt1b66 _123w1b66 _15nnze3t _rxygze3t _1a354jg8 _1j6r1odn _1uakf6fq _1kt9y7el _is06wx40 _1rus1tzq _1cfcvrvc _24gj1h6o _19o61h6o _cfu1116y _1rbawx40 _1xqc1rd4"
19
18
  };
@@ -1,6 +1,4 @@
1
1
  /* code-block.tsx generated by @compiled/babel-plugin v0.36.1 */
2
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-selectors */
3
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
4
2
  "use strict";
5
3
 
6
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -13,12 +11,16 @@ require("./code-block.compiled.css");
13
11
  var _react = _interopRequireWildcard(require("react"));
14
12
  var React = _react;
15
13
  var _runtime = require("@compiled/react/runtime");
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+ var _bindEventListener = require("bind-event-listener");
16
+ var _rafSchd = _interopRequireDefault(require("raf-schd"));
16
17
  var _useHighlight = require("./internal/hooks/use-highlight");
17
18
  var _styles = require("./internal/theme/styles");
18
19
  var _getNormalizedLanguage = require("./internal/utils/get-normalized-language");
19
20
  var _syntaxHighlighter = _interopRequireDefault(require("./syntax-highlighter"));
20
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
22
+ /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-selectors */
23
+ /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
22
24
  var getCodeBlockStyles = {
23
25
  root: "_2rkoglpi _1dqoglyw _1wyb1crf _k48pi7a9 _1e0c1txw _vwz4gktf _1reo1wug _o572qvpr _1eimjvyg _bfhktkvp _syaz1fxt _ect41odn _1ozdn7od _7xinn7od _t7aun7od _1v15u2gc _ilvcu2gc _m29uu2gc _17wyu2gc _pn28u2gc _gz9fu2gc _1hmyegat _vblregat _vbulegat _wozj1dyw _1agb1dyw _lkm81dyw _tv41hkgb _1hmimyb0 _1ra01n1a _1d4j1y44 _1f8gstnw _1pzyb3bt _j1w0ww7y _13cdh2mm _15ba126e _zvy9f705 _qcxof705 _14y71a66 _j0l11wug _1weckb7n _1na21hna _1xx2grf3 _x7c815vq _lh0y15vq _1m3815vq _qk1e15vq _12l6ysn8 _uga3ysn8 _mx8b7mnp _1kr87mnp _xo19t94y _1bemt94y _nalpstnw _151dstnw _1exb1q9c _1hgu1q9c _1mgnt94y _nhket94y _h909m7j4 _scgayz1z _ipl81e17 _jeky1l04 _1gec1a66 _1gx21e5h _1ls0df4r _vm2c1rh5 _12ok1rh5 _1ls01ule _rude1ule _1q16glyw _1io6glyw _juomusic _lcwuusic _1552u2gc _12afu2gc _28ddu2gc _1i8zu2gc _12tu1a66 _zu0j1a66 _euyxusvi _cahfusvi _zhnuidpf _1amdidpf _mbgcpf9b _bu7zpf9b _131n1giz _gy101giz _1wfuwrk5 _16kzwrk5 _9kk3moej _cjus1w1g _9k2r1m30 _nhmw1m30 _yl021m30 _eiht5x2v _t9zb5x2v _mqok1w1g _3hsg1w1g _i7ngn7od _9wu1fb2s _1xcoh55r _1t361fxt _137bh55r _1k7d1fxt _97lipnps _12nh9lu1 _1g0517qg _i2ig10m5 _326z1fxt _113p131l _1n6tpnps _tgu817qg _1k47pnps _g0lx1fxt _ys4e131l _7gp8h55r _1yvq10m5 _1vww10m5 _1rju10m5 _1v0lh55r _wmyy17qg _748n17qg _1mfn17qg _1d7e17qg _p2vr17qg _19o610m5 _kxov17qg _1np517qg _m2f517qg _1b9tpnps _1tq6pnps _1rd2pnps _1pbkpnps _k3lipnps _13zt131l _2g12fb2s _k86b10m5 _b5iy131l _gti3131l _1f0gpnps _9d3e17qg _qdiapnps _72uvpnps",
24
26
  showLineNumbers: "_17071olh _1i3h1txw _1huoidpf _1a9lidpf _20bqidpf _1oggidpf _bympidpf _9nnjidpf",
@@ -57,9 +59,31 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
57
59
  _ref$codeBidiWarningT = _ref.codeBidiWarningTooltipEnabled,
58
60
  codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
59
61
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
60
- shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
62
+ shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi,
63
+ _ref$label = _ref.label,
64
+ label = _ref$label === void 0 ? 'Scrollable content' : _ref$label;
65
+ var scrollableRef = (0, _react.useRef)(null);
66
+ var _useState = (0, _react.useState)(false),
67
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
68
+ showContentFocus = _useState2[0],
69
+ setShowContentFocus = _useState2[1];
61
70
  var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
62
71
  var lineNumberWidth = numLines ? (0, _styles.getLineNumWidth)(numLines) : 0;
72
+
73
+ // Schedule a content focus on the target element
74
+ // WARNING: In theory, `target` may not be available when `rafSchedule` hits in concurrent rendering
75
+ (0, _react.useEffect)(function () {
76
+ var schedule = (0, _rafSchd.default)(function () {
77
+ var target = scrollableRef.current;
78
+ target && setShowContentFocus(target.scrollWidth > target.clientWidth);
79
+ });
80
+ schedule();
81
+ var unbindWindowEvent = (0, _bindEventListener.bind)(window, {
82
+ type: 'resize',
83
+ listener: schedule
84
+ });
85
+ return unbindWindowEvent;
86
+ }, [scrollableRef]);
63
87
  var _useHighlightLines = (0, _useHighlight.useHighlightLines)({
64
88
  highlight: highlight,
65
89
  testId: testId
@@ -98,8 +122,11 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
98
122
  codeBidiWarningLabel: codeBidiWarningLabel,
99
123
  codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled,
100
124
  text: text,
125
+ tabIndex: showContentFocus ? '0' : undefined,
126
+ "aria-label": showContentFocus ? label : undefined,
127
+ role: showContentFocus ? 'region' : undefined,
128
+ scrollRef: scrollableRef,
101
129
  className: (0, _runtime.ax)([getCodeBlockStyles.root, shouldWrapLongLines ? getCodeBlockStyles.shouldWrapLongLines : getCodeBlockStyles.dontWrapLongLines, showLineNumbers ? getCodeBlockStyles.showLineNumbers : getCodeBlockStyles.dontShowLineNumbers])
102
130
  });
103
131
  });
104
- CodeBlock.displayName = 'CodeBlock';
105
132
  var _default = exports.default = CodeBlock;
package/dist/cjs/code.js CHANGED
@@ -16,8 +16,7 @@ var _bidiWarning = _interopRequireDefault(require("./bidi-warning"));
16
16
  var _bidiWarningDecorator = _interopRequireDefault(require("./bidi-warning/bidi-warning-decorator"));
17
17
  var _excluded = ["testId"],
18
18
  _excluded2 = ["children", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled"];
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
21
20
  var styles = {
22
21
  base: "_ca0qyh40 _u5f3m5ip _n3tdyh40 _19bvm5ip _2rko1sit _11c81u0j _1reo1wug _18m91wug _1dqoglyw _1e0c1nu9 _bfhktkvp _16d9qvcn _syaz1fxt _vwz41kw7 _1i4q1hna _o5721jtm"
23
22
  };
@@ -15,8 +15,7 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
15
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
16
  var _react = _interopRequireDefault(require("react"));
17
17
  var _highlight = _interopRequireDefault(require("./lib/highlight"));
18
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
19
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
19
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
21
20
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
22
21
  // Uses the loader method of async bundling
@@ -52,9 +52,13 @@ var Highlight = /*#__PURE__*/(0, _react.memo)(function Highlight(_ref) {
52
52
  var code = text;
53
53
  var generatorClassName = 'prismjs';
54
54
  var containerProps = _objectSpread(_objectSpread({}, rest), {}, {
55
+ ref: rest.scrollRef,
55
56
  'data-testid': testId,
56
57
  className: rest.className ? "".concat(generatorClassName, " ").concat(rest.className) : generatorClassName
57
58
  });
59
+ if (containerProps.hasOwnProperty('scrollRef')) {
60
+ delete containerProps['scrollRef'];
61
+ }
58
62
  if (shouldWrapLongLines) {
59
63
  codeTagProps.style = {
60
64
  whiteSpace: 'pre-wrap',
@@ -4,7 +4,9 @@
4
4
  import "./code-block.compiled.css";
5
5
  import * as React from 'react';
6
6
  import { ax, ix } from "@compiled/react/runtime";
7
- import { memo, useCallback, useMemo } from 'react';
7
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
+ import { bind } from 'bind-event-listener';
9
+ import rafSchedule from 'raf-schd';
8
10
  import { useHighlightLines } from './internal/hooks/use-highlight';
9
11
  import { getLineNumWidth } from './internal/theme/styles';
10
12
  import { normalizeLanguage } from './internal/utils/get-normalized-language';
@@ -38,10 +40,28 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
38
40
  codeBidiWarnings = true,
39
41
  codeBidiWarningLabel,
40
42
  codeBidiWarningTooltipEnabled = true,
41
- shouldWrapLongLines = false
43
+ shouldWrapLongLines = false,
44
+ label = 'Scrollable content'
42
45
  }) {
46
+ const scrollableRef = useRef(null);
47
+ const [showContentFocus, setShowContentFocus] = useState(false);
43
48
  const numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
44
49
  const lineNumberWidth = numLines ? getLineNumWidth(numLines) : 0;
50
+
51
+ // Schedule a content focus on the target element
52
+ // WARNING: In theory, `target` may not be available when `rafSchedule` hits in concurrent rendering
53
+ useEffect(() => {
54
+ const schedule = rafSchedule(() => {
55
+ const target = scrollableRef.current;
56
+ target && setShowContentFocus(target.scrollWidth > target.clientWidth);
57
+ });
58
+ schedule();
59
+ const unbindWindowEvent = bind(window, {
60
+ type: 'resize',
61
+ listener: schedule
62
+ });
63
+ return unbindWindowEvent;
64
+ }, [scrollableRef]);
45
65
  const {
46
66
  getHighlightStyles,
47
67
  highlightedLines
@@ -77,8 +97,11 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
77
97
  codeBidiWarningLabel: codeBidiWarningLabel,
78
98
  codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled,
79
99
  text: text,
100
+ tabIndex: showContentFocus ? '0' : undefined,
101
+ "aria-label": showContentFocus ? label : undefined,
102
+ role: showContentFocus ? 'region' : undefined,
103
+ scrollRef: scrollableRef,
80
104
  className: ax([getCodeBlockStyles.root, shouldWrapLongLines ? getCodeBlockStyles.shouldWrapLongLines : getCodeBlockStyles.dontWrapLongLines, showLineNumbers ? getCodeBlockStyles.showLineNumbers : getCodeBlockStyles.dontShowLineNumbers])
81
105
  });
82
106
  });
83
- CodeBlock.displayName = 'CodeBlock';
84
107
  export default CodeBlock;
@@ -34,9 +34,13 @@ const Highlight = /*#__PURE__*/memo(function Highlight({
34
34
  const generatorClassName = 'prismjs';
35
35
  const containerProps = {
36
36
  ...rest,
37
+ ref: rest.scrollRef,
37
38
  'data-testid': testId,
38
39
  className: rest.className ? `${generatorClassName} ${rest.className}` : generatorClassName
39
40
  };
41
+ if (containerProps.hasOwnProperty('scrollRef')) {
42
+ delete containerProps['scrollRef'];
43
+ }
40
44
  if (shouldWrapLongLines) {
41
45
  codeTagProps.style = {
42
46
  whiteSpace: 'pre-wrap',
@@ -1,10 +1,14 @@
1
1
  /* code-block.tsx generated by @compiled/babel-plugin v0.36.1 */
2
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-selectors */
3
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
3
  import "./code-block.compiled.css";
5
4
  import * as React from 'react';
6
5
  import { ax, ix } from "@compiled/react/runtime";
7
- import { memo, useCallback, useMemo } from 'react';
6
+ /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-selectors */
7
+ /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
8
+
9
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
+ import { bind } from 'bind-event-listener';
11
+ import rafSchedule from 'raf-schd';
8
12
  import { useHighlightLines } from './internal/hooks/use-highlight';
9
13
  import { getLineNumWidth } from './internal/theme/styles';
10
14
  import { normalizeLanguage } from './internal/utils/get-normalized-language';
@@ -47,9 +51,31 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
47
51
  _ref$codeBidiWarningT = _ref.codeBidiWarningTooltipEnabled,
48
52
  codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
49
53
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
50
- shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
54
+ shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi,
55
+ _ref$label = _ref.label,
56
+ label = _ref$label === void 0 ? 'Scrollable content' : _ref$label;
57
+ var scrollableRef = useRef(null);
58
+ var _useState = useState(false),
59
+ _useState2 = _slicedToArray(_useState, 2),
60
+ showContentFocus = _useState2[0],
61
+ setShowContentFocus = _useState2[1];
51
62
  var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
52
63
  var lineNumberWidth = numLines ? getLineNumWidth(numLines) : 0;
64
+
65
+ // Schedule a content focus on the target element
66
+ // WARNING: In theory, `target` may not be available when `rafSchedule` hits in concurrent rendering
67
+ useEffect(function () {
68
+ var schedule = rafSchedule(function () {
69
+ var target = scrollableRef.current;
70
+ target && setShowContentFocus(target.scrollWidth > target.clientWidth);
71
+ });
72
+ schedule();
73
+ var unbindWindowEvent = bind(window, {
74
+ type: 'resize',
75
+ listener: schedule
76
+ });
77
+ return unbindWindowEvent;
78
+ }, [scrollableRef]);
53
79
  var _useHighlightLines = useHighlightLines({
54
80
  highlight: highlight,
55
81
  testId: testId
@@ -88,8 +114,11 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
88
114
  codeBidiWarningLabel: codeBidiWarningLabel,
89
115
  codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled,
90
116
  text: text,
117
+ tabIndex: showContentFocus ? '0' : undefined,
118
+ "aria-label": showContentFocus ? label : undefined,
119
+ role: showContentFocus ? 'region' : undefined,
120
+ scrollRef: scrollableRef,
91
121
  className: ax([getCodeBlockStyles.root, shouldWrapLongLines ? getCodeBlockStyles.shouldWrapLongLines : getCodeBlockStyles.dontWrapLongLines, showLineNumbers ? getCodeBlockStyles.showLineNumbers : getCodeBlockStyles.dontShowLineNumbers])
92
122
  });
93
123
  });
94
- CodeBlock.displayName = 'CodeBlock';
95
124
  export default CodeBlock;
@@ -46,9 +46,13 @@ var Highlight = /*#__PURE__*/memo(function Highlight(_ref) {
46
46
  var code = text;
47
47
  var generatorClassName = 'prismjs';
48
48
  var containerProps = _objectSpread(_objectSpread({}, rest), {}, {
49
+ ref: rest.scrollRef,
49
50
  'data-testid': testId,
50
51
  className: rest.className ? "".concat(generatorClassName, " ").concat(rest.className) : generatorClassName
51
52
  });
53
+ if (containerProps.hasOwnProperty('scrollRef')) {
54
+ delete containerProps['scrollRef'];
55
+ }
52
56
  if (shouldWrapLongLines) {
53
57
  codeTagProps.style = {
54
58
  whiteSpace: 'pre-wrap',
@@ -70,6 +70,11 @@ export interface CodeBlockProps {
70
70
  * @default false
71
71
  */
72
72
  shouldWrapLongLines?: boolean;
73
+ /**
74
+ * Text used to describe that the content of the code block is scrollable.
75
+ * Set only if the code block is scrollable. Defaults to 'Scrollable content'.
76
+ */
77
+ label?: string;
73
78
  }
74
79
  export type { SupportedLanguages, LanguageAlias, Language } from '../constants';
75
80
  export type { CodeBlockTheme, CodeTheme } from './theme/types';
@@ -70,6 +70,11 @@ export interface CodeBlockProps {
70
70
  * @default false
71
71
  */
72
72
  shouldWrapLongLines?: boolean;
73
+ /**
74
+ * Text used to describe that the content of the code block is scrollable.
75
+ * Set only if the code block is scrollable. Defaults to 'Scrollable content'.
76
+ */
77
+ label?: string;
73
78
  }
74
79
  export type { SupportedLanguages, LanguageAlias, Language } from '../constants';
75
80
  export type { CodeBlockTheme, CodeTheme } from './theme/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "17.1.2",
3
+ "version": "17.2.1",
4
4
  "description": "Code highlights short strings of code snippets inline with body text.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,12 +30,14 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/codemod-utils": "^4.2.0",
32
32
  "@atlaskit/platform-feature-flags": "^1.1.0",
33
- "@atlaskit/tokens": "^4.8.0",
34
- "@atlaskit/tooltip": "^20.0.0",
33
+ "@atlaskit/tokens": "^5.0.0",
34
+ "@atlaskit/tooltip": "^20.2.0",
35
35
  "@atlaskit/visually-hidden": "^3.0.0",
36
36
  "@babel/runtime": "^7.0.0",
37
37
  "@compiled/react": "^0.18.3",
38
+ "bind-event-listener": "^3.0.0",
38
39
  "memoize-one": "^6.0.0",
40
+ "raf-schd": "^4.0.3",
39
41
  "refractor": "^3.6.0"
40
42
  },
41
43
  "peerDependencies": {
@@ -45,12 +47,12 @@
45
47
  "@af/accessibility-testing": "workspace:^",
46
48
  "@af/integration-testing": "workspace:^",
47
49
  "@af/visual-regression": "workspace:^",
48
- "@atlaskit/button": "^23.0.0",
50
+ "@atlaskit/button": "^23.2.0",
49
51
  "@atlaskit/docs": "^10.0.0",
50
52
  "@atlaskit/ds-lib": "^4.0.0",
51
53
  "@atlaskit/form": "^12.0.0",
52
- "@atlaskit/link": "^3.1.0",
53
- "@atlaskit/primitives": "^14.7.0",
54
+ "@atlaskit/link": "^3.2.0",
55
+ "@atlaskit/primitives": "^14.8.0",
54
56
  "@atlaskit/section-message": "^8.2.0",
55
57
  "@atlaskit/ssr": "workspace:^",
56
58
  "@atlaskit/theme": "^18.0.0",