Skip to content

Commit fd08d21

Browse files
committed
Address code review
1 parent a52c8c0 commit fd08d21

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

packages/circuit-ui/components/CurrencyInput/CurrencyInput.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveCurrencyFormat } from '@sumup-oss/intl';
2020
import { NumericFormat, type NumericFormatProps } from 'react-number-format';
2121

2222
import { clsx } from '../../styles/clsx.js';
23+
import { getBrowserLocale, type Locale } from '../../util/i18n.js';
2324
import { Input, type InputProps } from '../Input/index.js';
2425

2526
import { formatPlaceholder } from './CurrencyInputService.js';
@@ -37,10 +38,12 @@ export interface CurrencyInputProps
3738
*/
3839
currency: string;
3940
/**
40-
* One or more Unicode BCP 47 locale identifiers, such as 'de-DE' or
41-
* ['GB', 'en-US'] (the first supported locale is used).
41+
* One or more [IETF BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag)
42+
* locale identifiers such as `'de-DE'` or `['GB', 'en-US']`.
43+
* When passing an array, the first supported locale is used.
44+
* Defaults to `navigator.language` in supported environments.
4245
*/
43-
locale?: string | string[];
46+
locale?: Locale;
4447
/**
4548
* A short string that is shown inside the empty input.
4649
* If the placeholder is a number, it is formatted in the local
@@ -76,7 +79,7 @@ const DUMMY_DELIMITER = '?';
7679
export const CurrencyInput = forwardRef<HTMLInputElement, CurrencyInputProps>(
7780
(
7881
{
79-
locale,
82+
locale = getBrowserLocale(),
8083
currency,
8184
placeholder,
8285
'aria-describedby': descriptionId,

packages/circuit-ui/components/DateInput/DateInput.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ import * as Stories from './DateInput.stories';
77

88
<Status variant="stable" />
99

10-
The DateInput component allows user to type or select a specific date. The input value is always a string in the format `YYYY-MM-DD`.
10+
The DateInput component allows users to type or select a specific date. The input value is always a string in the format `YYYY-MM-DD`.
1111

1212
<Story of={Stories.Base} />
1313
<Props />
1414

1515
## Usage
1616

17-
Use the component whenever asking for a specific individual date such as a birth date, expiry date, or appointment date.
17+
Use the component whenever asking for a specific individual date such as a birth date, expiry date, or appointment date. The date is in the [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format (`YYYY-MM-DD`).
1818

1919
For selecting a range of dates, we expect to introduce an iteration of this component in the future. Until then, we recommend using a combination of two input fields (one for the start and the other for the end date).
2020

2121
## Validations
2222

23-
TODO: Decide on built-in validation.
24-
25-
Use the `validationHint` to communicate the expected response to users.
23+
Use the `validationHint` prop to communicate the expected response to users. The DateInput component ensures that the entered date is a valid date, but does not validate whether it falls within the minimum or maximum date range.
2624

2725
### Invalid
2826

29-
The user needs to change the value to proceed. This could be due to a
27+
The user needs to change the value to proceed. This could be because they entered a date outside of the allowed range.
3028

3129
### Warning
3230

@@ -49,3 +47,9 @@ Use the `optionalLabel` prop to indicate that the field is optional. This can he
4947
Use the `readOnly` prop to indicate that the field is not currently editable. This can be useful in situations where the user needs to view but not edit the date, such as in a summary or review screen.
5048

5149
<Story of={Stories.Readonly} />
50+
51+
## Internationalization
52+
53+
Pass one or more [IETF BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag) locale identifiers such as `'de-DE'` or `['GB', 'en-US']` to the `locale` prop to display the date in the local format. When passing an array, the first supported locale is used. Defaults to `navigator.language` in supported environments.
54+
55+
<Story of={Stories.Locales} />

packages/circuit-ui/components/DateInput/DateInput.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
z-index: var(--cui-z-index-absolute);
88
display: flex;
99
gap: 2px;
10+
min-width: 170px;
1011
padding: var(--cui-spacings-byte) var(--cui-spacings-mega);
1112
cursor: text;
1213
background-color: var(--cui-bg-normal);

packages/circuit-ui/components/DateInput/DateInput.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
FieldValidationHint,
4848
FieldWrapper,
4949
} from '../Field/Field.js';
50+
import { getBrowserLocale } from '../../util/i18n.js';
5051

5152
import { Dialog } from './components/Dialog.js';
5253
import { DateSegment } from './components/DateSegment.js';
@@ -140,7 +141,7 @@ export interface DateInputProps
140141
}
141142

142143
/**
143-
* The DateInput component allows user to type or select a specific date.
144+
* The DateInput component allows users to type or select a specific date.
144145
* The input value is always a string in the format `YYYY-MM-DD`.
145146
*/
146147
export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
@@ -152,7 +153,7 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
152153
onChange,
153154
min,
154155
max,
155-
locale,
156+
locale = getBrowserLocale(),
156157
firstDayOfWeek,
157158
modifiers,
158159
hideLabel,
@@ -181,7 +182,7 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
181182
) => {
182183
const isMobile = useMedia('(max-width: 479px)');
183184

184-
const referenceRef = useRef<HTMLDivElement>(null);
185+
const fieldRef = useRef<HTMLDivElement>(null);
185186
const floatingRef = useRef<HTMLDialogElement>(null);
186187
const calendarRef = useRef<HTMLDivElement>(null);
187188

@@ -209,7 +210,7 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
209210
placement: 'bottom-start',
210211
middleware: [offset(4), flip(), shift()],
211212
elements: {
212-
reference: referenceRef.current,
213+
reference: fieldRef.current,
213214
floating: floatingRef.current,
214215
},
215216
});
@@ -356,16 +357,16 @@ export const DateInput = forwardRef<HTMLDivElement, DateInputProps>(
356357
optionalLabel={optionalLabel}
357358
/>
358359
</FieldLegend>
359-
{/* biome-ignore lint/a11y/useKeyWithClickEvents: */}
360-
<div className={classes.wrapper} onClick={handleClick}>
360+
<div ref={fieldRef} className={classes.wrapper}>
361+
{/* biome-ignore lint/a11y/useKeyWithClickEvents: */}
361362
<div
363+
onClick={handleClick}
362364
className={clsx(
363365
classes.segments,
364366
invalid && classes.invalid,
365367
hasWarning && classes.warning,
366368
readOnly && classes.readonly,
367369
)}
368-
ref={referenceRef}
369370
>
370371
{segments.map((segment, index) => {
371372
const segmentProps = {

packages/circuit-ui/vendor/dialog-polyfill/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ if (typeof window === 'undefined') {
621621
* @param {!Element} element to force upgrade
622622
*/
623623
dialogPolyfill.forceRegisterDialog = function (element) {
624-
if (window.HTMLDialogElement && element.showModal) {
624+
if (window.HTMLDialogElement || element.showModal) {
625625
console.warn(
626626
'This browser already supports <dialog>, the polyfill ' +
627627
'may not work correctly',

0 commit comments

Comments
 (0)