Skip to content

Commit d5e8172

Browse files
authored
fix(web-components/file-input): add min-width to the input (#384)
* fix(web-components/file-input): add min-width to the input * update test command * update test scripts
1 parent 0dd3ff5 commit d5e8172

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

.github/workflows/development.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: pnpm install
5757

5858
- name: "🎭 install playwright"
59-
run: pnpx playwright install --with-deps --only-shell
59+
run: pnpm playwright install --with-deps --only-shell
6060

6161
- name: "🔍 run tests"
6262
run: pnpm test

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"playground:dev": "pnpm --filter @tapsioss/playground run start:dev",
3030
"playground:test": "pnpm --filter @tapsioss/playground run start:test",
3131
"dev": "run-p packages:dev playground:dev",
32-
"test": "pnpm run packages:build && pnpm run packages:test",
32+
"build": "pnpm run packages:build",
33+
"test": "pnpm run packages:test",
3334
"lint:ts": "tsc --project tsconfig.json",
3435
"lint:ecma": "eslint --fix",
3536
"lint": "run-p lint:*",

packages/web-components/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"build": "run-p gen:metadata bulld:compile",
1919
"bulld:compile": "tsc --project ./tsconfig.build.json",
2020
"predev": "pnpm run clear",
21+
"pretest": "pnpm --filter @tapsioss/theme run build && pnpm run build",
2122
"test": "playwright test",
2223
"dev": "tsc --watch --project ./tsconfig.dev.json",
2324
"release": "pnpm publish . --tag latest --access public",

packages/web-components/src/file-input/file-input.style.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default css`
3131
flex-direction: column;
3232
3333
gap: var(--tapsi-spacing-4);
34+
35+
width: 100%;
3436
}
3537
3638
.root.disabled {
@@ -68,7 +70,7 @@ export default css`
6870
justify-content: center;
6971
7072
height: 8.25rem;
71-
width: 100%;
73+
min-width: 8.25rem;
7274
}
7375
7476
.label {
@@ -102,7 +104,7 @@ export default css`
102104
}
103105
104106
.file-input {
105-
height: 8.25rem;
107+
height: 100%;
106108
width: 100%;
107109
108110
position: relative;

packages/web-components/src/file-input/file-input.ts

+7-22
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ import {
2828
import { ErrorMessages, scope, Slots } from "./constants.ts";
2929
import { RetryEvent } from "./events.ts";
3030
import { clear, error, image } from "./icons.ts";
31-
import { getProgressUiParams, isFileImage, isStringNumber } from "./utils.ts";
31+
import {
32+
getProgressUiParams,
33+
isFileImage,
34+
isStringNumber,
35+
loadingConverter,
36+
} from "./utils.ts";
3237
import FileInputValidator from "./Validator.ts";
3338

3439
const BaseClass = withOnReportValidity(
@@ -53,25 +58,7 @@ export class FileInput extends BaseClass {
5358
* - If `true`, a spinner will appear indicating the component is loading.
5459
* - If a number between 0 and 100, it shows the percentage of the loading state.
5560
*/
56-
@property({
57-
converter: {
58-
fromAttribute(value: string | null): boolean | number {
59-
if (value === null) return false;
60-
if (value === "") return true;
61-
62-
const numericValue = Number(value);
63-
64-
if (Number.isNaN(numericValue)) return true;
65-
66-
return numericValue;
67-
},
68-
toAttribute(value: boolean | number): string | null {
69-
if (typeof value === "boolean") return value ? "true" : null;
70-
71-
return `${value}`;
72-
},
73-
},
74-
})
61+
@property({ converter: loadingConverter })
7562
public loading: boolean | number = false;
7663

7764
/**
@@ -646,8 +633,6 @@ export class FileInput extends BaseClass {
646633
}
647634

648635
protected override render() {
649-
console.log(this.loading);
650-
651636
const rootClasses = classMap({
652637
root: true,
653638
disabled: this.disabled,

packages/web-components/src/file-input/utils.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { PropertyDeclaration } from "lit";
2+
13
export const isStringNumber = (inputString: string): boolean =>
24
/^\d+(\.\d+)?$/.test(inputString);
35

@@ -33,3 +35,21 @@ export const isFileImage = (fileName: string) => {
3335
fileName.toLowerCase().endsWith(imageExtension),
3436
);
3537
};
38+
39+
export const loadingConverter: PropertyDeclaration["converter"] = {
40+
fromAttribute(value: string | null): boolean | number {
41+
if (value === null) return false;
42+
if (value === "") return true;
43+
44+
const numericValue = Number(value);
45+
46+
if (Number.isNaN(numericValue)) return true;
47+
48+
return numericValue;
49+
},
50+
toAttribute(value: boolean | number): string | null {
51+
if (typeof value === "boolean") return value ? "true" : null;
52+
53+
return `${value}`;
54+
},
55+
};

0 commit comments

Comments
 (0)