Skip to content

Commit

Permalink
fix(input): expose textareaStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
koory1st committed Dec 9, 2023
1 parent e5b23aa commit 8404030
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"@svelement-ui/icon": "workspace:^",
"@svelement-ui/theme-chalk": "workspace:^",
"@svelement-ui/util-array-2-class-string": "workspace:^",
"@svelement-ui/util-array-2-style-string": "workspace:^"
"@svelement-ui/util-array-2-style-string": "workspace:^",
"to-style": "^1.3.3"
},
"repository": {
"type": "git",
Expand Down
23 changes: 13 additions & 10 deletions packages/input/src/lib/input.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import a2s from '@svelement-ui/util-array-2-class-string';
import a2st from '@svelement-ui/util-array-2-style-string';
import { string as toStyleObject } from 'to-style';
import { createEventDispatcher, onMount, tick } from 'svelte';
import { CircleClose, Hide, SvelIcon, View } from '@svelement-ui/icon';
Expand Down Expand Up @@ -60,6 +61,7 @@
// export let validateEvent = true;
/** @type {string | Object} */
export let inputStyle = {};
export let textareaStyle;
// eslint-disable-next-line svelte/valid-compile
export async function focus() {
Expand Down Expand Up @@ -108,9 +110,9 @@
}
const style = calcTextareaHeight(textAreaRef, minRows, maxRows);
style.push(['overflow-y', 'hidden']);
style['overflow-y'] = 'hidden';
return a2st(style);
return style;
}
export function select() {
Expand Down Expand Up @@ -188,10 +190,11 @@
await focus();
}
let textareaCalcStyle = '';
let textareaStyle;
let textareaCalcStyle = {};
let textareaStyleStr;
$: {
textareaStyle = a2st([inputStyle, textareaCalcStyle, ['resize', resize]]);
textareaStyle = { ...inputStyle, ...textareaCalcStyle, resize };
textareaStyleStr = toStyleObject(textareaStyle);
}
$: containerClass = a2s([
Expand Down Expand Up @@ -345,7 +348,7 @@
hiddenTextarea.value = targetElement.value || targetElement.placeholder || '';
let height = hiddenTextarea.scrollHeight;
const result = [];
const ret = {};
if (boxSizing === 'border-box') {
height = height + borderSize;
Expand All @@ -362,7 +365,7 @@
minHeight = minHeight + paddingSize + borderSize;
}
height = Math.max(minHeight, height);
result.push(['min-height', `${minHeight}px`]);
ret['min-height'] = `${minHeight}px`;
}
if (isNumber(maxRows)) {
let maxHeight = singleRowHeight * maxRows;
Expand All @@ -371,11 +374,11 @@
}
height = Math.min(maxHeight, height);
}
result.push(['height', `${height}px`]);
ret['height'] = `${height}px`;
hiddenTextarea.parentNode?.removeChild(hiddenTextarea);
hiddenTextarea = undefined;
return result;
return ret;
}
const CONTEXT_STYLE = [
Expand Down Expand Up @@ -581,7 +584,7 @@
aria-label={label}
{placeholder}
{rows}
style={textareaStyle}
style={textareaStyleStr}
{maxlength}
{name}
on:input={handleInput}
Expand Down
9 changes: 9 additions & 0 deletions packages/input/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
function invokeSelect() {
select();
}
let textareaStyle;
function showTextareaStyle() {
console.log(textareaStyle);
}
</script>

<SvelInput
Expand All @@ -52,8 +58,10 @@
bind:blur
bind:focus
bind:resizeTextarea
bind:textareaStyle
bind:value={textarea2}
placeholder="Please input"
resize="both"
type="textarea"
/>
<button on:click={showRef}>log ref</button>
Expand All @@ -63,3 +71,4 @@
<button on:click={clear}>clear</button>
<button on:click={invokeResize}>invokeText</button>
<button on:click={invokeSelect}>invokeSelect</button>
<button on:click={showTextareaStyle}>showTextareaStyle</button>
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8404030

Please sign in to comment.