@seed-design/react-field 1.0.0 → 2.0.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.
@@ -4,6 +4,7 @@ import { composeRefs } from '@radix-ui/react-compose-refs';
4
4
  import { elementProps, dataAttr, inputProps, labelProps, ariaAttr, mergeProps } from '@seed-design/dom-utils';
5
5
  import { Primitive } from '@seed-design/react-primitive';
6
6
  import { useId, useState, useCallback, createContext, useContext, forwardRef } from 'react';
7
+ import { useSupports } from '@seed-design/react-supports';
7
8
 
8
9
  const getLabelId = (id)=>`field:${id}:label`;
9
10
  const getInputId = (id)=>`field:${id}:input`;
@@ -51,6 +52,7 @@ function useFieldState() {
51
52
  function useField(props) {
52
53
  const id = useId();
53
54
  const { disabled = false, invalid = false, readOnly = false, required = false } = props;
55
+ const isFocusVisibleSupported = useSupports("selector(:focus-visible)");
54
56
  const { refs, renderedElements, isHovered, isActive, isFocused, isFocusVisible, setIsHovered, setIsActive, setIsFocused, setIsFocusVisible } = useFieldState();
55
57
  const ariaDescribedBy = [
56
58
  renderedElements.description ? getDescriptionId(id) : false,
@@ -113,15 +115,21 @@ function useField(props) {
113
115
  }),
114
116
  inputHandlers: inputProps({
115
117
  onChange: (event)=>{
116
- setIsFocusVisible(event.target.matches(":focus-visible"));
118
+ if (isFocusVisibleSupported) {
119
+ setIsFocusVisible(event.target.matches(":focus-visible"));
120
+ }
117
121
  },
118
122
  onBlur () {
119
123
  setIsFocused(false);
120
- setIsFocusVisible(false);
124
+ if (isFocusVisibleSupported) {
125
+ setIsFocusVisible(false);
126
+ }
121
127
  },
122
128
  onFocus (event) {
123
129
  setIsFocused(true);
124
- setIsFocusVisible(event.target.matches(":focus-visible"));
130
+ if (isFocusVisibleSupported) {
131
+ setIsFocusVisible(event.target.matches(":focus-visible"));
132
+ }
125
133
  }
126
134
  }),
127
135
  descriptionProps: elementProps({
@@ -4,6 +4,7 @@ var reactComposeRefs = require('@radix-ui/react-compose-refs');
4
4
  var domUtils = require('@seed-design/dom-utils');
5
5
  var reactPrimitive = require('@seed-design/react-primitive');
6
6
  var react = require('react');
7
+ var reactSupports = require('@seed-design/react-supports');
7
8
 
8
9
  const getLabelId = (id)=>`field:${id}:label`;
9
10
  const getInputId = (id)=>`field:${id}:input`;
@@ -51,6 +52,7 @@ function useFieldState() {
51
52
  function useField(props) {
52
53
  const id = react.useId();
53
54
  const { disabled = false, invalid = false, readOnly = false, required = false } = props;
55
+ const isFocusVisibleSupported = reactSupports.useSupports("selector(:focus-visible)");
54
56
  const { refs, renderedElements, isHovered, isActive, isFocused, isFocusVisible, setIsHovered, setIsActive, setIsFocused, setIsFocusVisible } = useFieldState();
55
57
  const ariaDescribedBy = [
56
58
  renderedElements.description ? getDescriptionId(id) : false,
@@ -113,15 +115,21 @@ function useField(props) {
113
115
  }),
114
116
  inputHandlers: domUtils.inputProps({
115
117
  onChange: (event)=>{
116
- setIsFocusVisible(event.target.matches(":focus-visible"));
118
+ if (isFocusVisibleSupported) {
119
+ setIsFocusVisible(event.target.matches(":focus-visible"));
120
+ }
117
121
  },
118
122
  onBlur () {
119
123
  setIsFocused(false);
120
- setIsFocusVisible(false);
124
+ if (isFocusVisibleSupported) {
125
+ setIsFocusVisible(false);
126
+ }
121
127
  },
122
128
  onFocus (event) {
123
129
  setIsFocused(true);
124
- setIsFocusVisible(event.target.matches(":focus-visible"));
130
+ if (isFocusVisibleSupported) {
131
+ setIsFocusVisible(event.target.matches(":focus-visible"));
132
+ }
125
133
  }
126
134
  }),
127
135
  descriptionProps: domUtils.elementProps({
package/lib/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- var Field12s = require('./Field-12s-DIDZP1t4.cjs');
1
+ var Field12s = require('./Field-12s-t41MRyBm.cjs');
2
2
 
3
3
  var Field_namespace = {
4
4
  __proto__: null,
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDescription, a as FieldErrorMessage, b as FieldLabel, c as FieldRoot } from './Field-12s-C77so-rw.js';
2
- export { u as useFieldContext } from './Field-12s-C77so-rw.js';
1
+ import { F as FieldDescription, a as FieldErrorMessage, b as FieldLabel, c as FieldRoot } from './Field-12s-D99__Wte.js';
2
+ export { u as useFieldContext } from './Field-12s-D99__Wte.js';
3
3
 
4
4
  var Field_namespace = {
5
5
  __proto__: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/react-field",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
@@ -28,8 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@radix-ui/react-compose-refs": "^1.1.2",
31
- "@seed-design/dom-utils": "1.0.0",
32
- "@seed-design/react-primitive": "1.0.0"
31
+ "@seed-design/dom-utils": "^2.0.0",
32
+ "@seed-design/react-primitive": "^2.0.0",
33
+ "@seed-design/react-supports": "^1.0.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/react": "^19.1.6",
@@ -1,7 +1,6 @@
1
- import "@testing-library/jest-dom/vitest";
2
- import { cleanup, fireEvent, render } from "@testing-library/react";
1
+ import { fireEvent, render } from "@testing-library/react";
3
2
  import userEvent from "@testing-library/user-event";
4
- import { afterEach, describe, expect, it } from "vitest";
3
+ import { describe, expect, it } from "bun:test";
5
4
 
6
5
  import {
7
6
  forwardRef,
@@ -20,8 +19,6 @@ import {
20
19
  } from "./Field";
21
20
  import { useFieldContext } from "./useFieldContext";
22
21
 
23
- afterEach(cleanup);
24
-
25
22
  function setUp(jsx: ReactElement) {
26
23
  return {
27
24
  user: userEvent.setup(),
package/src/useField.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ariaAttr, dataAttr, elementProps, inputProps, labelProps } from "@seed-design/dom-utils";
2
2
  import { useCallback, useId, useState } from "react";
3
3
  import { getDescriptionId, getErrorMessageId, getInputId, getLabelId } from "./dom";
4
+ import { useSupports } from "@seed-design/react-supports";
4
5
 
5
6
  function useFieldState() {
6
7
  const [isHovered, setIsHovered] = useState(false);
@@ -72,6 +73,8 @@ export function useField(props: UseFieldProps) {
72
73
  const id = useId();
73
74
  const { disabled = false, invalid = false, readOnly = false, required = false } = props;
74
75
 
76
+ const isFocusVisibleSupported = useSupports("selector(:focus-visible)");
77
+
75
78
  const {
76
79
  refs,
77
80
  renderedElements,
@@ -157,15 +160,21 @@ export function useField(props: UseFieldProps) {
157
160
  }),
158
161
  inputHandlers: inputProps({
159
162
  onChange: (event) => {
160
- setIsFocusVisible(event.target.matches(":focus-visible"));
163
+ if (isFocusVisibleSupported) {
164
+ setIsFocusVisible(event.target.matches(":focus-visible"));
165
+ }
161
166
  },
162
167
  onBlur() {
163
168
  setIsFocused(false);
164
- setIsFocusVisible(false);
169
+ if (isFocusVisibleSupported) {
170
+ setIsFocusVisible(false);
171
+ }
165
172
  },
166
173
  onFocus(event) {
167
174
  setIsFocused(true);
168
- setIsFocusVisible(event.target.matches(":focus-visible"));
175
+ if (isFocusVisibleSupported) {
176
+ setIsFocusVisible(event.target.matches(":focus-visible"));
177
+ }
169
178
  },
170
179
  }),
171
180