Skip to content

Commit

Permalink
Document new options and update method in shipping address element (#339
Browse files Browse the repository at this point in the history
)

* Document new shipping address element options
* Add shipping address update method
* Add type testing
  • Loading branch information
andywang-stripe committed Jul 30, 2022
1 parent 099c51c commit 0d6ab15
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,14 @@ const shippingAddressElement = elements.create('shippingAddress', {
},
},
disableAutocomplete: true,
fields: {
phone: 'always',
},
validation: {
phone: {
required: 'never',
},
},
});

shippingAddressElement
Expand All @@ -525,6 +533,14 @@ shippingAddressElement
}) => {}
);

shippingAddressElement.update({
validation: {
phone: {
required: 'always',
},
},
});

const retrievedShippingAddressElement: StripeShippingAddressElement | null = elements.getElement(
'shippingAddress'
);
Expand Down
26 changes: 26 additions & 0 deletions types/stripe-js/elements/shipping-address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export type StripeShippingAddressElement = StripeElementBase & {
eventType: 'loaderstart',
handler?: (event: {elementType: 'shippingAddress'}) => any
): StripeShippingAddressElement;

/**
* Updates the options the `ShippingAddressElement` was initialized with.
* Updates are merged into the existing configuration.
*/
update(
options: Partial<StripeShippingAddressElementOptions>
): StripeShippingAddressElement;
};

export interface StripeShippingAddressElementOptions {
Expand All @@ -148,12 +156,29 @@ export interface StripeShippingAddressElementOptions {
postal_code?: string | null;
country: string;
};
phone?: string | null;
};

/**
* Whether or not ShippingAddressElement provides autocomplete suggestions
*/
disableAutocomplete?: boolean;

/**
* Control which additional fields to display in the shippingAddress Element.
*/
fields?: {
phone?: 'always' | 'never' | 'auto';
};

/**
* Specify validation rules for the above additional fields.
*/
validation?: {
phone?: {
required: 'always' | 'never' | 'auto';
};
};
}

export interface StripeShippingAddressElementChangeEvent
Expand Down Expand Up @@ -191,5 +216,6 @@ export interface StripeShippingAddressElementChangeEvent
postal_code: string;
country: string;
};
phone?: string;
};
}

0 comments on commit 0d6ab15

Please sign in to comment.