From b4093dfef3eff0e5fe60d00c53fe2478b96e662f Mon Sep 17 00:00:00 2001 From: Robert Snow Date: Thu, 22 Aug 2024 11:13:39 +1000 Subject: [PATCH] Support and document preventFocusOnPress (#6854) Support and document preventFocusOnPress (#6854) --- packages/@react-aria/button/src/useButton.ts | 1 - .../@react-aria/combobox/src/useComboBox.ts | 1 - .../searchfield/src/useSearchField.ts | 1 - packages/@react-types/button/src/index.d.ts | 9 ++++++++- scripts/compareAPIs.js | 19 +++++++++++++++---- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/@react-aria/button/src/useButton.ts b/packages/@react-aria/button/src/useButton.ts index e431fecf7e0..e15a4e59bf5 100644 --- a/packages/@react-aria/button/src/useButton.ts +++ b/packages/@react-aria/button/src/useButton.ts @@ -55,7 +55,6 @@ export function useButton(props: AriaButtonOptions, ref: RefObject< onPressEnd, onPressUp, onPressChange, - // @ts-ignore - undocumented preventFocusOnPress, // @ts-ignore - undocumented allowFocusWhenDisabled, diff --git a/packages/@react-aria/combobox/src/useComboBox.ts b/packages/@react-aria/combobox/src/useComboBox.ts index 9659f1aa0e4..4cf9785195d 100644 --- a/packages/@react-aria/combobox/src/useComboBox.ts +++ b/packages/@react-aria/combobox/src/useComboBox.ts @@ -346,7 +346,6 @@ export function useComboBox(props: AriaComboBoxOptions, state: ComboBoxSta ...menuTriggerProps, ...triggerLabelProps, excludeFromTabOrder: true, - // @ts-ignore - undocumented preventFocusOnPress: true, onPress, onPressStart, diff --git a/packages/@react-aria/searchfield/src/useSearchField.ts b/packages/@react-aria/searchfield/src/useSearchField.ts index d9a0586c8f1..a8110c41e0e 100644 --- a/packages/@react-aria/searchfield/src/useSearchField.ts +++ b/packages/@react-aria/searchfield/src/useSearchField.ts @@ -116,7 +116,6 @@ export function useSearchField( clearButtonProps: { 'aria-label': stringFormatter.format('Clear search'), excludeFromTabOrder: true, - // @ts-ignore preventFocusOnPress: true, isDisabled: isDisabled || isReadOnly, onPress: onClearButtonClick, diff --git a/packages/@react-types/button/src/index.d.ts b/packages/@react-types/button/src/index.d.ts index 210d6bf0c0b..d9b2fc9fe8e 100644 --- a/packages/@react-types/button/src/index.d.ts +++ b/packages/@react-types/button/src/index.d.ts @@ -59,7 +59,14 @@ interface AriaBaseButtonProps extends FocusableDOMProps, AriaLabelingProps { * The behavior of the button when used in an HTML form. * @default 'button' */ - type?: 'button' | 'submit' | 'reset' + type?: 'button' | 'submit' | 'reset', + /** + * Whether to prevent focus from moving to the button when pressing it. + * + * Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, + * such as ComboBox's MenuTrigger or a NumberField's increment/decrement control. + */ + preventFocusOnPress?: boolean } export interface AriaButtonProps extends ButtonProps, LinkButtonProps, AriaBaseButtonProps {} diff --git a/scripts/compareAPIs.js b/scripts/compareAPIs.js index 784f5cd3111..cb6f8744d42 100644 --- a/scripts/compareAPIs.js +++ b/scripts/compareAPIs.js @@ -292,7 +292,7 @@ function getDiff(pair) { ${joinedResult} \`\`\``; } - diffs.push({iname, result: joinedResult, simplifiedName}); + diffs.push({iname, result: joinedResult, simplifiedName: `${name.replace('/dist/api.json', '')}:${simplifiedName}`}); }); return {diffs, name}; @@ -535,9 +535,20 @@ function rebuildInterfaces(json) { let name = property.name; let optional = property.optional; let defaultVal = property.default; - let value = processType(property.value); - // TODO: what to do with defaultVal and optional - funcInterface[name] = {optional, defaultVal, value}; + // this needs to handle types like spreads, but need to build that into the build API's first + if (!property.value) { + name = 'UNKNOWN'; + let i = 0; + while (funcInterface[name]) { + i++; + name = 'UNKNOWN' + String(i); + } + funcInterface[name] = {optional, defaultVal, value: property.type}; + } else { + let value = processType(property.value); + // TODO: what to do with defaultVal and optional + funcInterface[name] = {optional, defaultVal, value}; + } }); let name = item.name ?? key; if (item.typeParameters?.length > 0) {