@jobber/components 8.14.1 → 8.16.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.
- package/dist/Autocomplete-es.js +1 -1
- package/dist/BottomSheet-cjs.js +109 -77
- package/dist/BottomSheet-es.js +103 -75
- package/dist/Card/index.cjs +2 -3
- package/dist/Card/index.mjs +2 -3
- package/dist/DataDump/index.cjs +2 -3
- package/dist/DataDump/index.mjs +2 -3
- package/dist/InputNumberExperimental-cjs.js +16 -17
- package/dist/InputNumberExperimental-es.js +2 -3
- package/dist/Menu/index.cjs +2 -3
- package/dist/Menu/index.mjs +2 -3
- package/dist/Menu-cjs.js +11 -56
- package/dist/Menu-es.js +4 -49
- package/dist/MenuSubmenuTrigger-cjs.js +1608 -1793
- package/dist/MenuSubmenuTrigger-es.js +1340 -1522
- package/dist/Modal/index.mjs +1 -1
- package/dist/NumberFieldInput-cjs.js +53 -54
- package/dist/NumberFieldInput-es.js +2 -3
- package/dist/Page/index.cjs +2 -3
- package/dist/Page/index.mjs +2 -3
- package/dist/{DrawerRoot-cjs.js → ScrollAreaViewport-cjs.js} +5488 -4449
- package/dist/{DrawerRoot-es.js → ScrollAreaViewport-es.js} +5423 -4393
- package/dist/{useValueChanged-cjs.js → clamp-cjs.js} +573 -321
- package/dist/{useValueChanged-es.js → clamp-es.js} +569 -322
- package/dist/floating-ui.react-es.js +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.mjs +2 -3
- package/dist/primitives/BottomSheet/BottomSheet.d.ts +15 -16
- package/dist/primitives/BottomSheet/BottomSheet.types.d.ts +27 -0
- package/dist/primitives/BottomSheet/BottomSheet.utils.d.ts +6 -0
- package/dist/primitives/BottomSheet/index.cjs +8 -3
- package/dist/primitives/BottomSheet/index.d.ts +1 -0
- package/dist/primitives/BottomSheet/index.mjs +8 -3
- package/dist/primitives/InputNumberExperimental/index.cjs +2 -3
- package/dist/primitives/InputNumberExperimental/index.mjs +2 -3
- package/dist/primitives/index.cjs +8 -9
- package/dist/primitives/index.mjs +8 -9
- package/dist/styles.css +62 -1
- package/dist/unstyledPrimitives/index.cjs +6373 -5868
- package/dist/unstyledPrimitives/index.d.ts +2 -0
- package/dist/unstyledPrimitives/index.mjs +6325 -5822
- package/dist/useRenderElement-cjs.js +30 -30
- package/dist/useRenderElement-es.js +31 -31
- package/package.json +2 -2
- package/dist/useBaseUiId-cjs.js +0 -275
- package/dist/useBaseUiId-es.js +0 -251
|
@@ -217,32 +217,6 @@ function isSyntheticEvent(event) {
|
|
|
217
217
|
return event != null && typeof event === 'object' && 'nativeEvent' in event;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
/**
|
|
221
|
-
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
222
|
-
* @param baseUrl - The base URL for the error page (e.g., 'https://base-ui.com/production-error')
|
|
223
|
-
* @param prefix - The prefix for the error message (e.g., 'Base UI')
|
|
224
|
-
* @returns A function that formats error messages with the given URL and prefix
|
|
225
|
-
*/
|
|
226
|
-
function createFormatErrorMessage(baseUrl, prefix) {
|
|
227
|
-
return function formatErrorMessage(code, ...args) {
|
|
228
|
-
const url = new URL(baseUrl);
|
|
229
|
-
url.searchParams.set('code', code.toString());
|
|
230
|
-
args.forEach(arg => url.searchParams.append('args[]', arg));
|
|
231
|
-
return `${prefix} error #${code}; visit ${url} for the full message.`;
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
237
|
-
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
238
|
-
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
239
|
-
* throw new Error('My message');
|
|
240
|
-
* throw new Error(`My message: ${foo}`);
|
|
241
|
-
* throw new Error(`My message: ${foo}` + 'another string');
|
|
242
|
-
* ...
|
|
243
|
-
*/
|
|
244
|
-
const formatErrorMessage = createFormatErrorMessage('https://base-ui.com/production-error', 'Base UI');
|
|
245
|
-
|
|
246
220
|
const UNINITIALIZED = {};
|
|
247
221
|
|
|
248
222
|
/**
|
|
@@ -366,11 +340,41 @@ function update(forkRef, refs) {
|
|
|
366
340
|
};
|
|
367
341
|
}
|
|
368
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
345
|
+
* @param baseUrl - The base URL for the error page (e.g., 'https://base-ui.com/production-error')
|
|
346
|
+
* @param prefix - The prefix for the error message (e.g., 'Base UI')
|
|
347
|
+
* @returns A function that formats error messages with the given URL and prefix
|
|
348
|
+
*/
|
|
349
|
+
function createFormatErrorMessage(baseUrl, prefix) {
|
|
350
|
+
return function formatErrorMessage(code, ...args) {
|
|
351
|
+
const url = new URL(baseUrl);
|
|
352
|
+
url.searchParams.set('code', code.toString());
|
|
353
|
+
args.forEach(arg => url.searchParams.append('args[]', arg));
|
|
354
|
+
return `${prefix} error #${code}; visit ${url} for the full message.`;
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
360
|
+
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
361
|
+
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
362
|
+
* throw new Error('My message');
|
|
363
|
+
* throw new Error(`My message: ${foo}`);
|
|
364
|
+
* throw new Error(`My message: ${foo}` + 'another string');
|
|
365
|
+
* ...
|
|
366
|
+
*/
|
|
367
|
+
const formatErrorMessage = createFormatErrorMessage('https://base-ui.com/production-error', 'Base UI');
|
|
368
|
+
|
|
369
369
|
const majorVersion = parseInt(React__namespace.version, 10);
|
|
370
370
|
function isReactVersionAtLeast(reactVersionToCheck) {
|
|
371
371
|
return majorVersion >= reactVersionToCheck;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
function NOOP() {}
|
|
375
|
+
const EMPTY_ARRAY = Object.freeze([]);
|
|
376
|
+
const EMPTY_OBJECT = Object.freeze({});
|
|
377
|
+
|
|
374
378
|
/**
|
|
375
379
|
* Extracts the `ref` from a React element, handling different React versions.
|
|
376
380
|
*/
|
|
@@ -441,10 +445,6 @@ function resolveStyle(style, state) {
|
|
|
441
445
|
return typeof style === 'function' ? style(state) : style;
|
|
442
446
|
}
|
|
443
447
|
|
|
444
|
-
function NOOP() {}
|
|
445
|
-
const EMPTY_ARRAY = Object.freeze([]);
|
|
446
|
-
const EMPTY_OBJECT = Object.freeze({});
|
|
447
|
-
|
|
448
448
|
/**
|
|
449
449
|
* Renders a Base UI element.
|
|
450
450
|
*
|
|
@@ -197,32 +197,6 @@ function isSyntheticEvent(event) {
|
|
|
197
197
|
return event != null && typeof event === 'object' && 'nativeEvent' in event;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
/**
|
|
201
|
-
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
202
|
-
* @param baseUrl - The base URL for the error page (e.g., 'https://base-ui.com/production-error')
|
|
203
|
-
* @param prefix - The prefix for the error message (e.g., 'Base UI')
|
|
204
|
-
* @returns A function that formats error messages with the given URL and prefix
|
|
205
|
-
*/
|
|
206
|
-
function createFormatErrorMessage(baseUrl, prefix) {
|
|
207
|
-
return function formatErrorMessage(code, ...args) {
|
|
208
|
-
const url = new URL(baseUrl);
|
|
209
|
-
url.searchParams.set('code', code.toString());
|
|
210
|
-
args.forEach(arg => url.searchParams.append('args[]', arg));
|
|
211
|
-
return `${prefix} error #${code}; visit ${url} for the full message.`;
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
217
|
-
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
218
|
-
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
219
|
-
* throw new Error('My message');
|
|
220
|
-
* throw new Error(`My message: ${foo}`);
|
|
221
|
-
* throw new Error(`My message: ${foo}` + 'another string');
|
|
222
|
-
* ...
|
|
223
|
-
*/
|
|
224
|
-
const formatErrorMessage = createFormatErrorMessage('https://base-ui.com/production-error', 'Base UI');
|
|
225
|
-
|
|
226
200
|
const UNINITIALIZED = {};
|
|
227
201
|
|
|
228
202
|
/**
|
|
@@ -346,11 +320,41 @@ function update(forkRef, refs) {
|
|
|
346
320
|
};
|
|
347
321
|
}
|
|
348
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
325
|
+
* @param baseUrl - The base URL for the error page (e.g., 'https://base-ui.com/production-error')
|
|
326
|
+
* @param prefix - The prefix for the error message (e.g., 'Base UI')
|
|
327
|
+
* @returns A function that formats error messages with the given URL and prefix
|
|
328
|
+
*/
|
|
329
|
+
function createFormatErrorMessage(baseUrl, prefix) {
|
|
330
|
+
return function formatErrorMessage(code, ...args) {
|
|
331
|
+
const url = new URL(baseUrl);
|
|
332
|
+
url.searchParams.set('code', code.toString());
|
|
333
|
+
args.forEach(arg => url.searchParams.append('args[]', arg));
|
|
334
|
+
return `${prefix} error #${code}; visit ${url} for the full message.`;
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
340
|
+
* `@mui/internal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
341
|
+
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
342
|
+
* throw new Error('My message');
|
|
343
|
+
* throw new Error(`My message: ${foo}`);
|
|
344
|
+
* throw new Error(`My message: ${foo}` + 'another string');
|
|
345
|
+
* ...
|
|
346
|
+
*/
|
|
347
|
+
const formatErrorMessage = createFormatErrorMessage('https://base-ui.com/production-error', 'Base UI');
|
|
348
|
+
|
|
349
349
|
const majorVersion = parseInt(React.version, 10);
|
|
350
350
|
function isReactVersionAtLeast(reactVersionToCheck) {
|
|
351
351
|
return majorVersion >= reactVersionToCheck;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
function NOOP() {}
|
|
355
|
+
const EMPTY_ARRAY = Object.freeze([]);
|
|
356
|
+
const EMPTY_OBJECT = Object.freeze({});
|
|
357
|
+
|
|
354
358
|
/**
|
|
355
359
|
* Extracts the `ref` from a React element, handling different React versions.
|
|
356
360
|
*/
|
|
@@ -421,10 +425,6 @@ function resolveStyle(style, state) {
|
|
|
421
425
|
return typeof style === 'function' ? style(state) : style;
|
|
422
426
|
}
|
|
423
427
|
|
|
424
|
-
function NOOP() {}
|
|
425
|
-
const EMPTY_ARRAY = Object.freeze([]);
|
|
426
|
-
const EMPTY_OBJECT = Object.freeze({});
|
|
427
|
-
|
|
428
428
|
/**
|
|
429
429
|
* Renders a Base UI element.
|
|
430
430
|
*
|
|
@@ -566,4 +566,4 @@ function renderTag(Tag, props) {
|
|
|
566
566
|
return /*#__PURE__*/React.createElement(Tag, props);
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
-
export { EMPTY_OBJECT as E, NOOP as N,
|
|
569
|
+
export { EMPTY_OBJECT as E, NOOP as N, useRefWithInit as a, useMergedRefs as b, makeEventPreventable as c, EMPTY_ARRAY as d, formatErrorMessage as f, isReactVersionAtLeast as i, mergeProps as m, useRenderElement as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -546,5 +546,5 @@
|
|
|
546
546
|
"> 1%",
|
|
547
547
|
"IE 10"
|
|
548
548
|
],
|
|
549
|
-
"gitHead": "
|
|
549
|
+
"gitHead": "4e229c9d1f28566fb9117dd4b199efd2cbcebf9f"
|
|
550
550
|
}
|
package/dist/useBaseUiId-cjs.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var floatingUi_utils_dom = require('./floating-ui.utils.dom-cjs.js');
|
|
5
|
-
var useValueChanged = require('./useValueChanged-cjs.js');
|
|
6
|
-
var useRenderElement = require('./useRenderElement-cjs.js');
|
|
7
|
-
|
|
8
|
-
function _interopNamespaceDefault(e) {
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
|
-
|
|
27
|
-
let set;
|
|
28
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
-
set = new Set();
|
|
30
|
-
}
|
|
31
|
-
function error(...messages) {
|
|
32
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
33
|
-
const messageKey = messages.join(' ');
|
|
34
|
-
if (!set.has(messageKey)) {
|
|
35
|
-
set.add(messageKey);
|
|
36
|
-
console.error(`Base UI: ${messageKey}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const CompositeRootContext = /*#__PURE__*/React__namespace.createContext(undefined);
|
|
42
|
-
if (process.env.NODE_ENV !== "production") CompositeRootContext.displayName = "CompositeRootContext";
|
|
43
|
-
function useCompositeRootContext(optional = false) {
|
|
44
|
-
const context = React__namespace.useContext(CompositeRootContext);
|
|
45
|
-
if (context === undefined && !optional) {
|
|
46
|
-
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.' : useRenderElement.formatErrorMessage(16));
|
|
47
|
-
}
|
|
48
|
-
return context;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function useFocusableWhenDisabled(parameters) {
|
|
52
|
-
const {
|
|
53
|
-
focusableWhenDisabled,
|
|
54
|
-
disabled,
|
|
55
|
-
composite = false,
|
|
56
|
-
tabIndex: tabIndexProp = 0,
|
|
57
|
-
isNativeButton
|
|
58
|
-
} = parameters;
|
|
59
|
-
const isFocusableComposite = composite && focusableWhenDisabled !== false;
|
|
60
|
-
const isNonFocusableComposite = composite && focusableWhenDisabled === false;
|
|
61
|
-
|
|
62
|
-
// we can't explicitly assign `undefined` to any of these props because it
|
|
63
|
-
// would otherwise prevent subsequently merged props from setting them
|
|
64
|
-
const props = React__namespace.useMemo(() => {
|
|
65
|
-
const additionalProps = {
|
|
66
|
-
// allow Tabbing away from focusableWhenDisabled elements
|
|
67
|
-
onKeyDown(event) {
|
|
68
|
-
if (disabled && focusableWhenDisabled && event.key !== 'Tab') {
|
|
69
|
-
event.preventDefault();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
if (!composite) {
|
|
74
|
-
additionalProps.tabIndex = tabIndexProp;
|
|
75
|
-
if (!isNativeButton && disabled) {
|
|
76
|
-
additionalProps.tabIndex = focusableWhenDisabled ? tabIndexProp : -1;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (isNativeButton && (focusableWhenDisabled || isFocusableComposite) || !isNativeButton && disabled) {
|
|
80
|
-
additionalProps['aria-disabled'] = disabled;
|
|
81
|
-
}
|
|
82
|
-
if (isNativeButton && (!focusableWhenDisabled || isNonFocusableComposite)) {
|
|
83
|
-
additionalProps.disabled = disabled;
|
|
84
|
-
}
|
|
85
|
-
return additionalProps;
|
|
86
|
-
}, [composite, disabled, focusableWhenDisabled, isFocusableComposite, isNonFocusableComposite, isNativeButton, tabIndexProp]);
|
|
87
|
-
return {
|
|
88
|
-
props
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function useButton(parameters = {}) {
|
|
93
|
-
const {
|
|
94
|
-
disabled = false,
|
|
95
|
-
focusableWhenDisabled,
|
|
96
|
-
tabIndex = 0,
|
|
97
|
-
native: isNativeButton = true,
|
|
98
|
-
composite: compositeProp
|
|
99
|
-
} = parameters;
|
|
100
|
-
const elementRef = React__namespace.useRef(null);
|
|
101
|
-
const compositeRootContext = useCompositeRootContext(true);
|
|
102
|
-
const isCompositeItem = compositeProp ?? compositeRootContext !== undefined;
|
|
103
|
-
const {
|
|
104
|
-
props: focusableWhenDisabledProps
|
|
105
|
-
} = useFocusableWhenDisabled({
|
|
106
|
-
focusableWhenDisabled,
|
|
107
|
-
disabled,
|
|
108
|
-
composite: isCompositeItem,
|
|
109
|
-
tabIndex,
|
|
110
|
-
isNativeButton
|
|
111
|
-
});
|
|
112
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
113
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
114
|
-
React__namespace.useEffect(() => {
|
|
115
|
-
if (!elementRef.current) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const isButtonTag = isButtonElement(elementRef.current);
|
|
119
|
-
if (isNativeButton) {
|
|
120
|
-
if (!isButtonTag) {
|
|
121
|
-
const ownerStackMessage = useValueChanged.SafeReact.captureOwnerStack?.() || '';
|
|
122
|
-
const message = 'A component that acts as a button expected a native <button> because the ' + '`nativeButton` prop is true. Rendering a non-<button> removes native button ' + 'semantics, which can impact forms and accessibility. Use a real <button> in the ' + '`render` prop, or set `nativeButton` to `false`.';
|
|
123
|
-
error(`${message}${ownerStackMessage}`);
|
|
124
|
-
}
|
|
125
|
-
} else if (isButtonTag) {
|
|
126
|
-
const ownerStackMessage = useValueChanged.SafeReact.captureOwnerStack?.() || '';
|
|
127
|
-
const message = 'A component that acts as a button expected a non-<button> because the `nativeButton` ' + 'prop is false. Rendering a <button> keeps native behavior while Base UI applies ' + 'non-native attributes and handlers, which can add unintended extra attributes (such ' + 'as `role` or `aria-disabled`). Use a non-<button> in the `render` prop, or set ' + '`nativeButton` to `true`.';
|
|
128
|
-
error(`${message}${ownerStackMessage}`);
|
|
129
|
-
}
|
|
130
|
-
}, [isNativeButton]);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// handles a disabled composite button rendering another button, e.g.
|
|
134
|
-
// <Toolbar.Button disabled render={<Menu.Trigger />} />
|
|
135
|
-
// the `disabled` prop needs to pass through 2 `useButton`s then finally
|
|
136
|
-
// delete the `disabled` attribute from DOM
|
|
137
|
-
const updateDisabled = React__namespace.useCallback(() => {
|
|
138
|
-
const element = elementRef.current;
|
|
139
|
-
if (!isButtonElement(element)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (isCompositeItem && disabled && focusableWhenDisabledProps.disabled === undefined && element.disabled) {
|
|
143
|
-
element.disabled = false;
|
|
144
|
-
}
|
|
145
|
-
}, [disabled, focusableWhenDisabledProps.disabled, isCompositeItem]);
|
|
146
|
-
useValueChanged.useIsoLayoutEffect(updateDisabled, [updateDisabled]);
|
|
147
|
-
const getButtonProps = React__namespace.useCallback((externalProps = {}) => {
|
|
148
|
-
const {
|
|
149
|
-
onClick: externalOnClick,
|
|
150
|
-
onMouseDown: externalOnMouseDown,
|
|
151
|
-
onKeyUp: externalOnKeyUp,
|
|
152
|
-
onKeyDown: externalOnKeyDown,
|
|
153
|
-
onPointerDown: externalOnPointerDown,
|
|
154
|
-
...otherExternalProps
|
|
155
|
-
} = externalProps;
|
|
156
|
-
const type = isNativeButton ? 'button' : undefined;
|
|
157
|
-
return useRenderElement.mergeProps({
|
|
158
|
-
type,
|
|
159
|
-
onClick(event) {
|
|
160
|
-
if (disabled) {
|
|
161
|
-
event.preventDefault();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
externalOnClick?.(event);
|
|
165
|
-
},
|
|
166
|
-
onMouseDown(event) {
|
|
167
|
-
if (!disabled) {
|
|
168
|
-
externalOnMouseDown?.(event);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
onKeyDown(event) {
|
|
172
|
-
if (disabled) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
useRenderElement.makeEventPreventable(event);
|
|
176
|
-
externalOnKeyDown?.(event);
|
|
177
|
-
if (event.baseUIHandlerPrevented) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const isCurrentTarget = event.target === event.currentTarget;
|
|
181
|
-
const currentTarget = event.currentTarget;
|
|
182
|
-
const isButton = isButtonElement(currentTarget);
|
|
183
|
-
const isLink = !isNativeButton && isValidLinkElement(currentTarget);
|
|
184
|
-
const shouldClick = isCurrentTarget && (isNativeButton ? isButton : !isLink);
|
|
185
|
-
const isEnterKey = event.key === 'Enter';
|
|
186
|
-
const isSpaceKey = event.key === ' ';
|
|
187
|
-
const role = currentTarget.getAttribute('role');
|
|
188
|
-
const isTextNavigationRole = role?.startsWith('menuitem') || role === 'option' || role === 'gridcell';
|
|
189
|
-
if (isCurrentTarget && isCompositeItem && isSpaceKey) {
|
|
190
|
-
if (event.defaultPrevented && isTextNavigationRole) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
event.preventDefault();
|
|
194
|
-
if (isLink || isNativeButton && isButton) {
|
|
195
|
-
currentTarget.click();
|
|
196
|
-
event.preventBaseUIHandler();
|
|
197
|
-
} else if (shouldClick) {
|
|
198
|
-
externalOnClick?.(event);
|
|
199
|
-
event.preventBaseUIHandler();
|
|
200
|
-
}
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Keyboard accessibility for native and non-native elements.
|
|
205
|
-
if (shouldClick) {
|
|
206
|
-
if (!isNativeButton && (isSpaceKey || isEnterKey)) {
|
|
207
|
-
event.preventDefault();
|
|
208
|
-
}
|
|
209
|
-
if (!isNativeButton && isEnterKey) {
|
|
210
|
-
externalOnClick?.(event);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
onKeyUp(event) {
|
|
215
|
-
if (disabled) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// calling preventDefault in keyUp on a <button> will not dispatch a click event if Space is pressed
|
|
220
|
-
// https://codesandbox.io/p/sandbox/button-keyup-preventdefault-dn7f0
|
|
221
|
-
useRenderElement.makeEventPreventable(event);
|
|
222
|
-
externalOnKeyUp?.(event);
|
|
223
|
-
if (event.target === event.currentTarget && isNativeButton && isCompositeItem && isButtonElement(event.currentTarget) && event.key === ' ') {
|
|
224
|
-
event.preventDefault();
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (event.baseUIHandlerPrevented) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Keyboard accessibility for non interactive elements
|
|
232
|
-
if (event.target === event.currentTarget && !isNativeButton && !isCompositeItem && event.key === ' ') {
|
|
233
|
-
externalOnClick?.(event);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
onPointerDown(event) {
|
|
237
|
-
if (disabled) {
|
|
238
|
-
event.preventDefault();
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
externalOnPointerDown?.(event);
|
|
242
|
-
}
|
|
243
|
-
}, !isNativeButton ? {
|
|
244
|
-
role: 'button'
|
|
245
|
-
} : undefined, focusableWhenDisabledProps, otherExternalProps);
|
|
246
|
-
}, [disabled, focusableWhenDisabledProps, isCompositeItem, isNativeButton]);
|
|
247
|
-
const buttonRef = useValueChanged.useStableCallback(element => {
|
|
248
|
-
elementRef.current = element;
|
|
249
|
-
updateDisabled();
|
|
250
|
-
});
|
|
251
|
-
return {
|
|
252
|
-
getButtonProps,
|
|
253
|
-
buttonRef
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
function isButtonElement(elem) {
|
|
257
|
-
return floatingUi_utils_dom.isHTMLElement(elem) && elem.tagName === 'BUTTON';
|
|
258
|
-
}
|
|
259
|
-
function isValidLinkElement(elem) {
|
|
260
|
-
return Boolean(elem?.tagName === 'A' && elem?.href);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Wraps `useId` and prefixes generated `id`s with `base-ui-`
|
|
265
|
-
* @param {string | undefined} idOverride overrides the generated id when provided
|
|
266
|
-
* @returns {string | undefined}
|
|
267
|
-
*/
|
|
268
|
-
function useBaseUiId(idOverride) {
|
|
269
|
-
return useValueChanged.useId(idOverride, 'base-ui');
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
exports.error = error;
|
|
273
|
-
exports.useBaseUiId = useBaseUiId;
|
|
274
|
-
exports.useButton = useButton;
|
|
275
|
-
exports.useCompositeRootContext = useCompositeRootContext;
|