mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-12 17:40:52 +01:00
kalk_web autofocus prop
This commit is contained in:
parent
8b8ebec500
commit
57d82207ed
@ -39,6 +39,7 @@ The colours in the component can be changed by using these attributes.
|
||||
```html
|
||||
<kalk-calculator
|
||||
hinttext="Type something..."
|
||||
autofocus="true"
|
||||
identifiercolor="cornflowerblue"
|
||||
operatorcolor="darkorange"
|
||||
promptcolor="mediumseagreen"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@paddim8/kalk-component",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
|
||||
"svelte": "src/main.ts",
|
||||
"main": "public/build/bundle.js",
|
||||
|
@ -37,7 +37,7 @@
|
||||
<body>
|
||||
<section id="wrapper">
|
||||
<div class="calculator">
|
||||
<kalk-calculator hinttext="test">
|
||||
<kalk-calculator hinttext="test" autofocus="true">
|
||||
<console-line>kalk</console-line>
|
||||
<console-line>
|
||||
<span class="hint">Type 'help' for instructions.</span>
|
||||
|
@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { afterUpdate } from "svelte";
|
||||
import ConsoleLine from "./ConsoleLine.svelte";
|
||||
import type { Context } from "@paddim8/kalk";
|
||||
|
||||
// Props, HTML doesn't recognise them if they're not like this
|
||||
@ -10,6 +9,7 @@
|
||||
export let errorcolor = "tomato";
|
||||
export let linkcolor = "cornflowerblue";
|
||||
export let hinttext = "";
|
||||
export let autofocus = false;
|
||||
|
||||
type Kalk = typeof import("@paddim8/kalk");
|
||||
|
||||
@ -114,6 +114,10 @@
|
||||
setCursorPos(target, cursorPos - offset);
|
||||
}
|
||||
|
||||
function focus(element: HTMLInputElement) {
|
||||
if (autofocus) element.focus();
|
||||
}
|
||||
|
||||
function getCursorPos(element: HTMLInputElement): number {
|
||||
const selection = window.getSelection();
|
||||
if (selection.rangeCount !== 0) {
|
||||
@ -316,6 +320,7 @@
|
||||
contenteditable="true"
|
||||
class="input"
|
||||
placeholder={hinttext}
|
||||
use:focus
|
||||
on:keydown={(event) => handleKeyDown(event, kalk)}
|
||||
on:keyup={handleKeyUp}
|
||||
on:input={handleInput}
|
||||
|
Loading…
Reference in New Issue
Block a user