From bfed11ac3dae475ab5e1160d4b832edc97cfc8f3 Mon Sep 17 00:00:00 2001 From: Tim Layton Date: Mon, 19 Aug 2019 16:42:48 -0700 Subject: [PATCH 1/3] allow min and max to accept a string --- src/components/TextField/TextField.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/TextField/TextField.tsx b/src/components/TextField/TextField.tsx index b83142c8e58..a4d41368e07 100644 --- a/src/components/TextField/TextField.tsx +++ b/src/components/TextField/TextField.tsx @@ -87,12 +87,12 @@ export interface BaseProps { step?: number; /** Enable automatic completion by the browser */ autoComplete?: boolean | string; - /** Mimics the behavior of the native HTML attribute, limiting how high the spinner can increment the value */ - max?: number; + /** Mimics the behavior of the native HTML attribute, limiting the maximum value */ + max?: number | string; /** Maximum character length for an input */ maxLength?: number; - /** Mimics the behavior of the native HTML attribute, limiting how low the spinner can decrement the value */ - min?: number; + /** Mimics the behavior of the native HTML attribute, limiting the minimum value */ + min?: number | string; /** Minimum character length for an input */ minLength?: number; /** A regular expression to check the value against */ From 3fa05f20a6c574c1416cf99b2062e50ea18355cd Mon Sep 17 00:00:00 2001 From: Tim Layton Date: Mon, 19 Aug 2019 16:54:16 -0700 Subject: [PATCH 2/3] add changelog entry --- UNRELEASED.md | 1 + 1 file changed, 1 insertion(+) diff --git a/UNRELEASED.md b/UNRELEASED.md index e22a6ef38fa..c7a9eb9d887 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -13,6 +13,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f ### Bug fixes - Fixed animation for Modal when being rendered asynchronously ([#2076](https://github.com/Shopify/polaris-react/pull/2076)) +- Updated `TextField` `min` and `max` type from `number` to `number | string` to allow min/max dates ([#1991](https://github.com/Shopify/polaris-react/pull/1991)) ### Documentation From 07cf04b8ba9ba7482801826b566acfcac76165d3 Mon Sep 17 00:00:00 2001 From: Tim Layton Date: Mon, 19 Aug 2019 16:54:42 -0700 Subject: [PATCH 3/3] convert min/max to number when used with a number stepper --- src/components/TextField/TextField.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/TextField/TextField.tsx b/src/components/TextField/TextField.tsx index a4d41368e07..a300dddd06b 100644 --- a/src/components/TextField/TextField.tsx +++ b/src/components/TextField/TextField.tsx @@ -432,7 +432,10 @@ class TextField extends React.PureComponent { // step / value has. const decimalPlaces = Math.max(dpl(numericValue), dpl(step)); - const newValue = Math.min(max, Math.max(numericValue + steps * step, min)); + const newValue = Math.min( + Number(max), + Math.max(numericValue + steps * step, Number(min)), + ); onChange(String(newValue.toFixed(decimalPlaces)), this.state.id); };