@team-monolith/cds 1.97.1 → 1.97.2

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.
@@ -15,16 +15,38 @@ import { css } from "@emotion/react";
15
15
  import styled from "@emotion/styled";
16
16
  import React from "react";
17
17
  import { Tooltip as MuiTooltip, } from "@mui/material";
18
+ /**
19
+ * ReactElement를 받아서 tabIndex를 부여하여 focusable한 element로 변환합니다.
20
+ * 만약
21
+ * 1. 이미 네이티브 포커스 가능한 컨트롤이거나,
22
+ * 2. 비활성화 속성이 있어서 포커스가 불가능한 상태거나,
23
+ * 3. tabIndex가 의도적으로 음수로 설정되어 있으면
24
+ * 그대로 반환합니다.
25
+ */
26
+ function getFocusableElement(element) {
27
+ var _a;
28
+ // element.props 접근시 ValidElement가 아닌 경우 런타임에러가 발생합니다.
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ if (!React.isValidElement(element)) {
31
+ return element;
32
+ }
33
+ const { type, props } = element;
34
+ const isNativeControl = typeof type === "string" &&
35
+ ["button", "a", "input", "textarea", "select"].includes(type);
36
+ const isDisabled = props.disabled === true;
37
+ if (isNativeControl || isDisabled) {
38
+ return element;
39
+ }
40
+ return React.cloneElement(element, {
41
+ tabIndex: (_a = props.tabIndex) !== null && _a !== void 0 ? _a : 0,
42
+ });
43
+ }
18
44
  /**
19
45
  * [피그마](https://www.figma.com/file/yhrRFizzmhPoHdw9FbYow2/Codle-PD-Kit---Components?type=design&node-id=172-626&t=aFkKTFgWq2xFFGC5-0)
20
46
  */
21
47
  export const Tooltip = React.forwardRef(function Tooltip(props, ref) {
22
- var _a;
23
48
  const { title, text, children } = props, restProps = __rest(props, ["title", "text", "children"]);
24
- // children을 focusable하게 만듭니다.
25
- const focusableChildren = React.cloneElement(children, {
26
- tabIndex: (_a = children.props.tabIndex) !== null && _a !== void 0 ? _a : 0,
27
- });
49
+ const focusableChildren = getFocusableElement(children);
28
50
  return (_jsx(StyledTooltip, Object.assign({ ref: ref, title:
29
51
  // title이 없고 text가 null인 경우 툴팁을 표시하지 않음
30
52
  !title && text === null ? null : (_jsxs(_Fragment, { children: [title && _jsx(TitleDiv, { children: title }), text] })), describeChild: true }, restProps, { children: focusableChildren })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.97.1",
3
+ "version": "1.97.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,