@seed-design/react-field 1.0.0 → 1.0.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.
|
@@ -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
|
-
|
|
118
|
+
if (isFocusVisibleSupported) {
|
|
119
|
+
setIsFocusVisible(event.target.matches(":focus-visible"));
|
|
120
|
+
}
|
|
117
121
|
},
|
|
118
122
|
onBlur () {
|
|
119
123
|
setIsFocused(false);
|
|
120
|
-
|
|
124
|
+
if (isFocusVisibleSupported) {
|
|
125
|
+
setIsFocusVisible(false);
|
|
126
|
+
}
|
|
121
127
|
},
|
|
122
128
|
onFocus (event) {
|
|
123
129
|
setIsFocused(true);
|
|
124
|
-
|
|
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
|
-
|
|
118
|
+
if (isFocusVisibleSupported) {
|
|
119
|
+
setIsFocusVisible(event.target.matches(":focus-visible"));
|
|
120
|
+
}
|
|
117
121
|
},
|
|
118
122
|
onBlur () {
|
|
119
123
|
setIsFocused(false);
|
|
120
|
-
|
|
124
|
+
if (isFocusVisibleSupported) {
|
|
125
|
+
setIsFocusVisible(false);
|
|
126
|
+
}
|
|
121
127
|
},
|
|
122
128
|
onFocus (event) {
|
|
123
129
|
setIsFocused(true);
|
|
124
|
-
|
|
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
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-
|
|
2
|
-
export { u as useFieldContext } from './Field-12s-
|
|
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.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/daangn/seed-design.git",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@radix-ui/react-compose-refs": "^1.1.2",
|
|
31
31
|
"@seed-design/dom-utils": "1.0.0",
|
|
32
|
-
"@seed-design/react-primitive": "1.0.0"
|
|
32
|
+
"@seed-design/react-primitive": "1.0.0",
|
|
33
|
+
"@seed-design/react-supports": "0.0.1"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/react": "^19.1.6",
|
package/src/useField.test.tsx
CHANGED
|
@@ -92,6 +92,11 @@ const Field = forwardRef<HTMLDivElement, TestFieldProps>(
|
|
|
92
92
|
Field.displayName = "Field";
|
|
93
93
|
|
|
94
94
|
describe("Field components", () => {
|
|
95
|
+
global.CSS = {
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
supports: (_k, _v) => true,
|
|
98
|
+
};
|
|
99
|
+
|
|
95
100
|
describe("basic functionality", () => {
|
|
96
101
|
it("should render as a label element", () => {
|
|
97
102
|
const { getByTestId } = 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
|
-
|
|
163
|
+
if (isFocusVisibleSupported) {
|
|
164
|
+
setIsFocusVisible(event.target.matches(":focus-visible"));
|
|
165
|
+
}
|
|
161
166
|
},
|
|
162
167
|
onBlur() {
|
|
163
168
|
setIsFocused(false);
|
|
164
|
-
|
|
169
|
+
if (isFocusVisibleSupported) {
|
|
170
|
+
setIsFocusVisible(false);
|
|
171
|
+
}
|
|
165
172
|
},
|
|
166
173
|
onFocus(event) {
|
|
167
174
|
setIsFocused(true);
|
|
168
|
-
|
|
175
|
+
if (isFocusVisibleSupported) {
|
|
176
|
+
setIsFocusVisible(event.target.matches(":focus-visible"));
|
|
177
|
+
}
|
|
169
178
|
},
|
|
170
179
|
}),
|
|
171
180
|
|