Skip to content

Commit

Permalink
set autofocus on Cancel only for Open Team Membership for now
Browse files Browse the repository at this point in the history
  • Loading branch information
oioki committed Dec 20, 2024
1 parent 39e60ec commit e592e58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion static/app/components/confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export type OpenConfirmOptions = {
* Header of modal
*/
header?: React.ReactNode;
/**
* By default, the Confirm button has autofocus.
* However, if `isDangerous` is true, the Cancel button receives autofocus instead,
* preventing users from accidental modification of dangerous settings.
*/
isDangerous?: boolean;
/**
* Message to display to user when asking for confirmation
*/
Expand Down Expand Up @@ -213,6 +219,7 @@ type ModalProps = ModalRenderProps &
| 'confirmText'
| 'cancelText'
| 'header'
| 'isDangerous'
| 'onConfirm'
| 'onCancel'
| 'disableConfirmButton'
Expand Down Expand Up @@ -298,6 +305,7 @@ class ConfirmModal extends Component<ModalProps, ModalState> {
confirmText,
cancelText,
header,
isDangerous,
renderConfirmButton,
renderCancelButton,
} = this.props;
Expand All @@ -315,7 +323,7 @@ class ConfirmModal extends Component<ModalProps, ModalState> {
) : (
<Button
onClick={this.handleClose}
autoFocus
autoFocus={!!isDangerous}
aria-label={typeof cancelText === 'string' ? cancelText : t('Cancel')}
>
{cancelText ?? t('Cancel')}
Expand All @@ -332,6 +340,7 @@ class ConfirmModal extends Component<ModalProps, ModalState> {
disabled={this.state.disableConfirmButton}
priority={priority}
onClick={this.handleConfirm}
autoFocus={!isDangerous}
aria-label={typeof confirmText === 'string' ? confirmText : t('Confirm')}
>
{confirmText ?? t('Confirm')}
Expand Down
4 changes: 3 additions & 1 deletion static/app/components/forms/fields/booleanField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface BooleanFieldProps extends InputFieldProps {
false?: React.ReactNode;
true?: React.ReactNode;
};
isDangerous?: boolean;
}

export default class BooleanField extends Component<BooleanFieldProps> {
Expand All @@ -33,7 +34,7 @@ export default class BooleanField extends Component<BooleanFieldProps> {
};

render() {
const {confirm, ...fieldProps} = this.props;
const {confirm, isDangerous, ...fieldProps} = this.props;

return (
<FormField {...fieldProps} resetOnError>
Expand Down Expand Up @@ -71,6 +72,7 @@ export default class BooleanField extends Component<BooleanFieldProps> {
<Confirm
renderMessage={() => confirm[(!value).toString()]}
onConfirm={() => handleChange({})}
isDangerous={isDangerous}
>
{({open}) => (
<Tooltip title={disabledReason} skipWrapper disabled={!disabled}>
Expand Down
1 change: 1 addition & 0 deletions static/app/components/forms/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface BaseField {
hideLabel?: boolean;
// TODO(ts): FormField prop?
inline?: boolean;
isDangerous?: boolean;
label?: React.ReactNode | (() => React.ReactNode);
/**
* May be used to give the field an aria-label when the field's label is a
Expand Down
1 change: 1 addition & 0 deletions static/app/data/forms/organizationMembershipSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const formGroups: JsonFormObject[] = [
type: 'boolean',
label: t('Open Team Membership'),
help: t('Allow organization members to freely join any team'),
isDangerous: true,
confirm: {
true: t(
'This will allow any members of your organization to freely join any team and access any project of your organization. Do you want to continue?'
Expand Down

0 comments on commit e592e58

Please sign in to comment.