diff --git a/src/components/Form/Controls/EditInPlace/EditInPlace.module.css b/src/components/Form/Controls/EditInPlace/EditInPlace.module.css index 01271b8f..a48b526b 100644 --- a/src/components/Form/Controls/EditInPlace/EditInPlace.module.css +++ b/src/components/Form/Controls/EditInPlace/EditInPlace.module.css @@ -15,7 +15,7 @@ limitations under the License. */ .container { - min-block-size: 110px; + min-block-size: 124px; } .label { @@ -76,6 +76,7 @@ limitations under the License. inline-size: 100%; } +.container-show-buttons .button-group, .container:focus-within .button-group { display: inline-grid; } diff --git a/src/components/Form/Controls/EditInPlace/EditInPlace.stories.tsx b/src/components/Form/Controls/EditInPlace/EditInPlace.stories.tsx index ac6955a0..89660a35 100644 --- a/src/components/Form/Controls/EditInPlace/EditInPlace.stories.tsx +++ b/src/components/Form/Controls/EditInPlace/EditInPlace.stories.tsx @@ -37,6 +37,7 @@ export default { "savedLabel", "saveButtonLabel", "cancelButtonLabel", + "disableSaveButton", ], }, design: { @@ -52,7 +53,7 @@ export default { type: "string", }, disableSaveButton: { - type: "string", + type: "boolean", }, onChange: { action: "changed", diff --git a/src/components/Form/Controls/EditInPlace/EditInPlace.tsx b/src/components/Form/Controls/EditInPlace/EditInPlace.tsx index 09e0d1ec..b568f484 100644 --- a/src/components/Form/Controls/EditInPlace/EditInPlace.tsx +++ b/src/components/Form/Controls/EditInPlace/EditInPlace.tsx @@ -68,7 +68,7 @@ type Props = { saveButtonLabel: string; /** - * True to disable the save button, false to enasble. + * True to disable the save button, false to enable. * Default: false (enabled) */ disableSaveButton?: boolean; @@ -103,12 +103,15 @@ export const EditInPlace = forwardRef( const id = useId(); const labelId = useId(); const errorTextId = useId(); + + const [showSaved, setShowSaved] = React.useState(false); + const [saving, setSaving] = React.useState(false); + const classes = classnames(styles.container, className, { [styles["container-error"]]: Boolean(error), + [styles["container-show-buttons"]]: saving, }); - const [showSaved, setShowSaved] = React.useState(false); - const hideTimer = useRef(null); const saveButtonRef = useRef(null); @@ -124,6 +127,7 @@ export const EditInPlace = forwardRef( async (e: FormEvent) => { e.preventDefault(); try { + setSaving(true); await onSave(); saveButtonRef.current?.blur(); setShowSaved(true); @@ -134,6 +138,8 @@ export const EditInPlace = forwardRef( // We don't really need to do anything here, we just don't want to display the // 'saved' label, obviously. The user of the component can update the error to // show what failed. + } finally { + setSaving(false); } }, [setShowSaved, onSave, hideTimer], @@ -157,6 +163,7 @@ export const EditInPlace = forwardRef( aria-labelledby={labelId} aria-invalid={Boolean(error)} aria-errormessage={error ? errorTextId : undefined} + disabled={saving} />
@@ -179,6 +186,7 @@ export const EditInPlace = forwardRef( onClick={onCancelButtonClicked} aria-controls={id} aria-label={cancelButtonLabel} + disabled={saving} >