Skip to content

Commit f6f5805

Browse files
committed
Remove form and write on enter
1 parent bf6641c commit f6f5805

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,3 @@ Web Components library for micro:bit
4545

4646
### Firmware
4747
- [ ] Update Firmware
48-
49-
50-
buttons disappear with no text
51-
remove form, enter chsnre too

src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export namespace Components {
183183
/**
184184
* The text shown on the button
185185
*/
186-
'buttonText': string;
186+
'buttonLabel': string;
187187
/**
188188
* The speed to scroll the text
189189
*/
@@ -194,7 +194,7 @@ export namespace Components {
194194
/**
195195
* The text shown on the button
196196
*/
197-
'buttonText'?: string;
197+
'buttonLabel'?: string;
198198
/**
199199
* The speed to scroll the text
200200
*/

src/components/information/microbit-name.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ export class MicrobitName {
1414
@Prop() disconnectedText: string = "Disconnected";
1515

1616
render() {
17-
return (
18-
<div>{this.getText()}</div>
19-
);
20-
}
21-
22-
private getText(): string {
2317
return this.device ? this.device.name : this.disconnectedText;
2418
}
2519
}

src/components/led/microbit-text.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class MicrobitText {
1212
/**
1313
* The text shown on the button
1414
*/
15-
@Prop() buttonText: string = "Write";
15+
@Prop() buttonLabel: string = "";
1616

1717
/**
1818
* The speed to scroll the text
@@ -33,20 +33,37 @@ export class MicrobitText {
3333
}
3434

3535
render() {
36+
let button: JSX.Element;
37+
38+
if (this.buttonLabel) {
39+
button = <input
40+
type="submit"
41+
disabled={this.disabled}
42+
value={this.buttonLabel}
43+
onClick={() => this.writeText()}></input>;
44+
}
45+
3646
return (
37-
<form onSubmit={e => this.handleSubmit(e)}>
38-
<input type="input" disabled={this.disabled} maxLength={20} onChange={text => this.handleChange(text)}></input>
39-
<input type="submit" disabled={this.disabled} value={this.buttonText}></input>
40-
</form>
47+
<span>
48+
<input
49+
type="input"
50+
disabled={this.disabled}
51+
maxLength={20}
52+
onKeyPress={e => this.handleKeyPress(e)}></input>
53+
{button}
54+
</span>
4155
);
4256
}
4357

44-
private handleChange(event) {
45-
this.text = event.target.value;
58+
private handleKeyPress(event) {
59+
if (event.keyCode == 13) {
60+
this.writeText();
61+
} else {
62+
this.text = event.target.value;
63+
}
4664
}
4765

48-
private handleSubmit(event) {
49-
event.preventDefault();
66+
private writeText() {
5067
this.services.ledService.writeText(this.text);
5168
}
5269
}

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<microbit-temperature></microbit-temperature>
3333
</div>
3434
<div>
35-
<microbit-text></microbit-text>
35+
<microbit-text button-label="Write"></microbit-text>
3636
</div>
3737
</microbit-app>
3838
</body>

0 commit comments

Comments
 (0)