@itwin/itwinui-react 3.4.2 → 3.5.0

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/cjs/core/ProgressIndicators/ProgressLinear.js +6 -1
  3. package/cjs/core/ProgressIndicators/ProgressRadial.js +8 -3
  4. package/cjs/core/Select/Select.d.ts +3 -1
  5. package/cjs/core/Select/Select.js +1 -1
  6. package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +4 -2
  7. package/cjs/core/ToggleSwitch/ToggleSwitch.js +5 -11
  8. package/cjs/core/Typography/Anchor.d.ts +21 -1
  9. package/cjs/core/Typography/Anchor.js +38 -3
  10. package/cjs/core/VisuallyHidden/VisuallyHidden.js +19 -3
  11. package/cjs/core/utils/components/ShadowRoot.d.ts +2 -1
  12. package/cjs/core/utils/components/ShadowRoot.js +19 -4
  13. package/cjs/core/utils/functions/polymorphic.d.ts +5 -3
  14. package/cjs/core/utils/functions/polymorphic.js +20 -5
  15. package/cjs/core/utils/icons/Svg.js +5 -1
  16. package/esm/core/ProgressIndicators/ProgressLinear.js +7 -2
  17. package/esm/core/ProgressIndicators/ProgressRadial.js +9 -4
  18. package/esm/core/Select/Select.d.ts +3 -1
  19. package/esm/core/Select/Select.js +1 -1
  20. package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +4 -2
  21. package/esm/core/ToggleSwitch/ToggleSwitch.js +6 -12
  22. package/esm/core/Typography/Anchor.d.ts +21 -1
  23. package/esm/core/Typography/Anchor.js +11 -2
  24. package/esm/core/VisuallyHidden/VisuallyHidden.js +19 -3
  25. package/esm/core/utils/components/ShadowRoot.d.ts +2 -1
  26. package/esm/core/utils/components/ShadowRoot.js +19 -4
  27. package/esm/core/utils/functions/polymorphic.d.ts +5 -3
  28. package/esm/core/utils/functions/polymorphic.js +20 -5
  29. package/esm/core/utils/icons/Svg.js +5 -1
  30. package/package.json +3 -3
  31. package/styles.css +34 -33
@@ -6,24 +6,39 @@ import * as React from 'react';
6
6
  import * as ReactDOM from 'react-dom';
7
7
  const isBrowser = typeof document !== 'undefined';
8
8
  const supportsDSD = isBrowser && 'shadowRootMode' in HTMLTemplateElement.prototype;
9
+ const supportsAdoptedStylesheets = isBrowser && 'adoptedStyleSheets' in Document.prototype;
9
10
  /**
10
11
  * Wrapper around `<template>` element that attaches shadow root to its parent
11
12
  * and moves its children into the shadow root.
12
13
  *
13
14
  * @private
14
15
  */
15
- export const ShadowRoot = ({ children }) => {
16
+ export const ShadowRoot = ({ children, css, }) => {
16
17
  const [shadowRoot, setShadowRoot] = React.useState();
17
18
  const isFirstRender = useIsFirstRender();
19
+ const styleSheet = React.useRef();
18
20
  const attachShadowRef = React.useCallback((template) => {
19
21
  const parent = template?.parentElement;
20
22
  if (!template || !parent) {
21
23
  return;
22
24
  }
23
- queueMicrotask(() => ReactDOM.flushSync(() => setShadowRoot(parent.shadowRoot || parent.attachShadow({ mode: 'open' }))));
24
- }, []);
25
+ if (parent.shadowRoot) {
26
+ parent.shadowRoot.replaceChildren(); // Remove previous shadowroot content
27
+ }
28
+ queueMicrotask(() => {
29
+ const shadow = parent.shadowRoot || parent.attachShadow({ mode: 'open' });
30
+ if (css && supportsAdoptedStylesheets) {
31
+ styleSheet.current || (styleSheet.current = new CSSStyleSheet());
32
+ styleSheet.current.replaceSync(css);
33
+ shadow.adoptedStyleSheets = [styleSheet.current];
34
+ }
35
+ ReactDOM.flushSync(() => setShadowRoot(shadow));
36
+ });
37
+ }, [css]);
25
38
  if (!isBrowser) {
26
- return React.createElement("template", { shadowrootmode: 'open' }, children);
39
+ return (React.createElement("template", { shadowrootmode: 'open' },
40
+ css && React.createElement("style", null, css),
41
+ children));
27
42
  }
28
43
  // In browsers that support DSD, the template will be automatically removed as soon as it's parsed.
29
44
  // To pass hydration, the first client render needs to emulate this browser behavior and return null.
@@ -3,11 +3,13 @@ import type { PolymorphicForwardRefComponent } from '../props.js';
3
3
  /**
4
4
  * Utility to create a type-safe polymorphic component with a simple class.
5
5
  *
6
- * Can be called directly or as a property of the `Polymorphic` object.
6
+ * Can be called directly or as a property of the `polymorphic` object.
7
7
  * In both cases, returns a component that:
8
+ * - uses CSS-modules scoped classes
8
9
  * - supports `as` prop with default element
9
- * - forwards ref and rest props
10
- * - adds and merges css classes
10
+ * - forwards ref and spreads rest props
11
+ * - adds and merges CSS classes
12
+ * - adds tabIndex to interactive elements (Safari workaround)
11
13
  *
12
14
  * @example
13
15
  * const MyPolyDiv = polymorphic('my-poly-div');
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
6
  import * as React from 'react';
6
7
  import cx from 'classnames';
7
8
  import { useGlobals } from '../hooks/useGlobals.js';
@@ -9,9 +10,21 @@ import styles from '../../../styles.js';
9
10
  const _base = (defaultElement) => {
10
11
  return (className, attrs) => {
11
12
  const Comp = React.forwardRef(({ as = defaultElement, ...props }, ref) => {
12
- const Element = as || 'div'; // eslint-disable-line
13
+ props = {
14
+ ...attrs,
15
+ ...props,
16
+ className: getScopedClassName(cx(className, attrs?.className, props.className)),
17
+ };
18
+ const Element = as || 'div';
19
+ // Add tabIndex to interactive elements if not already set.
20
+ // Workaround for Safari refusing to focus links/buttons/non-text inputs.
21
+ if (Element === 'button' ||
22
+ Element === 'a' ||
23
+ (Element === 'input' && props.type === 'checkbox')) {
24
+ props.tabIndex ?? (props.tabIndex = 0);
25
+ }
13
26
  useGlobals();
14
- return (React.createElement(Element, { ref: ref, ...attrs, ...props, className: getScopedClassName(cx(className, attrs?.className, props.className)) }));
27
+ return React.createElement(Element, { ref: ref, ...props });
15
28
  });
16
29
  Comp.displayName = getDisplayNameFromClass(className);
17
30
  return Comp;
@@ -20,11 +33,13 @@ const _base = (defaultElement) => {
20
33
  /**
21
34
  * Utility to create a type-safe polymorphic component with a simple class.
22
35
  *
23
- * Can be called directly or as a property of the `Polymorphic` object.
36
+ * Can be called directly or as a property of the `polymorphic` object.
24
37
  * In both cases, returns a component that:
38
+ * - uses CSS-modules scoped classes
25
39
  * - supports `as` prop with default element
26
- * - forwards ref and rest props
27
- * - adds and merges css classes
40
+ * - forwards ref and spreads rest props
41
+ * - adds and merges CSS classes
42
+ * - adds tabIndex to interactive elements (Safari workaround)
28
43
  *
29
44
  * @example
30
45
  * const MyPolyDiv = polymorphic('my-poly-div');
@@ -3,4 +3,8 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { polymorphic } from '../functions/polymorphic.js';
6
- export const Svg = polymorphic.svg('', { viewBox: '0 0 16 16' });
6
+ export const Svg = polymorphic.svg('', {
7
+ viewBox: '0 0 16 16',
8
+ width: 16,
9
+ height: 16,
10
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "3.4.2",
3
+ "version": "3.5.0",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -85,8 +85,8 @@
85
85
  "tslib": "^2.6.0"
86
86
  },
87
87
  "devDependencies": {
88
- "@itwin/itwinui-css": "^2.3.1",
89
- "@itwin/itwinui-variables": "3.0.0",
88
+ "@itwin/itwinui-css": "^2.4.0",
89
+ "@itwin/itwinui-variables": "3.1.0",
90
90
  "@swc/cli": "^0.1.62",
91
91
  "@swc/core": "^1.3.68",
92
92
  "@testing-library/jest-dom": "^6.3.0",