Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
- text: Label
- textbox "Label"
- status
- link "Example - Types arrow_up_right\" / \""
- link "Example - Types with min and max arrow_up_right\" / \""
- text: Label
- textbox "Label"
- status
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/input/input.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
hasVoiceOver,
isArrayOfStrings,
stringPropVisible,
uuid
uuid,
getInputValue
} from '../../utils';
import { DBInputProps, DBInputState } from './model';
import {
Expand Down Expand Up @@ -221,8 +222,8 @@ export default function DBInput(props: DBInputProps) {
value={props.value ?? state._value}
maxLength={getNumber(props.maxLength, props.maxlength)}
minLength={getNumber(props.minLength, props.minlength)}
max={getNumber(props.max)}
min={getNumber(props.min)}
max={getInputValue(props.max, props.type)}
min={getInputValue(props.min, props.type)}
readOnly={
getBoolean(props.readOnly, 'readOnly') ||
getBoolean(props.readonly, 'readonly')
Expand Down
19 changes: 19 additions & 0 deletions packages/components/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ export const getNumber = (
return Number(originNumber ?? alternativeNumber);
};

/**
* Retrieves the input value based on the provided value and input type.
*
* If the input type is "number" or "range", the value is processed as a number.
* Otherwise, the value is returned as-is.
*
* @param value - The input value, which can be a number, string, or undefined.
* @param inputType - The type of the input, such as "number", "range", or other string types.
* @returns The processed input value as a string, number, or undefined.
*/
export const getInputValue = (
value?: number | string,
inputType?: string
): string | number | undefined => {
return inputType && ['number', 'range'].includes(inputType)
? getNumber(value)
: value;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getHideProp = (show?: boolean | string): any => {
if (show === undefined || show === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
>
<db-input
[maxLength]="exampleProps?.maxLength"
[max]="exampleProps?.max"
[min]="exampleProps?.min"
[variant]="exampleProps?.variant"
[label]="exampleProps?.label"
[message]="exampleProps?.message"
Expand Down
6 changes: 5 additions & 1 deletion showcases/react-showcase/src/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const getInput = ({
validMessage,
validation,
invalidMessage,
maxLength
maxLength,
max,
min
}: DBInputProps & { dataList: boolean }) => {
return (
<DBInput
Expand All @@ -58,6 +60,8 @@ const getInput = ({
readOnly={readOnly}
iconAfter={iconAfter}
maxLength={maxLength}
max={max}
min={min}
icon={icon}
showMessage={showMessage}
invalidMessage={invalidMessage}
Expand Down
22 changes: 16 additions & 6 deletions showcases/shared/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
]
},
{
"name": "Example - Types",
"name": "Example - Types with min and max",
"codeFileName": "ExampleTypes",
"examples": [
{
Expand Down Expand Up @@ -299,35 +299,45 @@
"name": "Date",
"props": {
"label": "Label",
"type": "date"
"type": "date",
"min": "2023-01-01",
"max": "2030-12-31"
}
},
{
"name": "Datetime Local",
"props": {
"label": "Label",
"type": "datetime-local"
"type": "datetime-local",
"min": "2023-01-01T00:00",
"max": "2030-12-31T23:59"
}
},
{
"name": "Month",
"props": {
"label": "Label",
"type": "month"
"type": "month",
"min": "2023-01",
"max": "2030-12"
}
},
{
"name": "Time",
"props": {
"label": "Label",
"type": "time"
"type": "time",
"min": "00:00",
"max": "23:59"
}
},
{
"name": "Week",
"props": {
"label": "Label",
"type": "week"
"type": "week",
"min": "2023-W01",
"max": "2030-W52"
}
}
]
Expand Down
2 changes: 2 additions & 0 deletions showcases/vue-showcase/src/components/input/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const getDataList = (
>
<DBInput
:maxLength="exampleProps?.maxLength"
:max="exampleProps?.max"
:min="exampleProps?.min"
:variant="exampleProps?.variant"
:show-label="exampleProps?.showLabel"
:label="exampleProps?.label"
Expand Down
Loading