Skip to content

Commit

Permalink
The <UpdateItemQuantity /> component now accepts textInputProps t…
Browse files Browse the repository at this point in the history
…o be passed to the `<TextInputNumber/>`.
  • Loading branch information
paales committed Jan 29, 2024
1 parent 83ecb7d commit 2e6afd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-months-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/magento-cart-items': patch
---

The `<UpdateItemQuantity />` component now accepts `textInputProps` to be passed to the `<TextInputNumber/>`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApolloCartErrorSnackbar, useFormGqlMutationCart } from '@graphcommerce/magento-cart'
import { TextInputNumber } from '@graphcommerce/next-ui'
import { TextInputNumber, TextInputNumberProps } from '@graphcommerce/next-ui'
import { useFormAutoSubmit, UseFormGraphQlOptions } from '@graphcommerce/react-hook-form'
import { SxProps, Theme } from '@mui/material'
import React from 'react'
Expand All @@ -15,15 +15,17 @@ type UpdateItemQuantityFormReturn = UseFormGraphQlOptions<
>

export type UpdateItemQuantityProps = Omit<UpdateItemQuantityMutationVariables, 'cartId'> & {
formOptions?: Omit<UpdateItemQuantityFormReturn, 'mode' | 'defaultValues'>
textInputProps?: TextInputNumberProps
sx?: SxProps<Theme>
} & Omit<UpdateItemQuantityFormReturn, 'mode' | 'defaultValues'>
}

export function UpdateItemQuantity(props: UpdateItemQuantityProps) {
const { uid, quantity, sx, ...formProps } = props
const { uid, quantity, sx, textInputProps, formOptions } = props
const form = useFormGqlMutationCart(UpdateItemQuantityDocument, {
defaultValues: { uid, quantity },
mode: 'onChange',
...formProps,
...formOptions,
})
const { muiRegister, required, handleSubmit, formState, error, reset } = form

Expand All @@ -41,6 +43,7 @@ export function UpdateItemQuantity(props: UpdateItemQuantityProps) {
{...muiRegister('quantity', { required: required.quantity })}
helperText={formState.errors.quantity?.message}
sx={sx}
{...textInputProps}
/>
<ApolloCartErrorSnackbar error={error} onClose={() => reset({ quantity })} />
</form>
Expand Down

0 comments on commit 2e6afd9

Please sign in to comment.