Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 45 Text input may need to prevent default/bubble #211

Merged
merged 2 commits into from
Dec 2, 2024
Merged
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
55 changes: 19 additions & 36 deletions src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,7 @@
isMobile.any && this.handleActivation(); // handleActivation always call before this function called.
});

if (isMobile.any)
{
window.addEventListener('touchstart', this.handleActivationBinding);
}
else if (!isMobile.any)
{
window.addEventListener('click', this.handleActivationBinding);

window.addEventListener('keyup', this.onKeyUpBinding);

window.addEventListener('input', this.onInputBinding as EventListener);
}
window.addEventListener(isMobile.any ? 'touchstart' : 'click', this.handleActivationBinding);

this.onEnter = new Signal();
this.onChange = new Signal();
Expand All @@ -169,6 +158,10 @@
{
const key = e.key;

const keysToSkip = ['Shift', 'Control', 'Alt', 'Meta', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'];

if (keysToSkip.includes(key)) return;

if (key === 'Backspace')
{
this._delete();
Expand All @@ -178,13 +171,18 @@
this.stopEditing();
}
else if (key.length === 1)
{

Check warning on line 174 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines

this._add(key);
}
else if (this.lastInputData && this.lastInputData.length === 1)
{
this._add(this.lastInputData);
}

if (this.input) {

Check warning on line 183 in src/Input.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
this.input.value = '';
}
}

protected init()
Expand Down Expand Up @@ -331,10 +329,7 @@
this.placeholder.visible = false;
this._cursor.alpha = 1;

if (isMobile.any)
{
this.createInputField();
}
this.createInputField();

this.align();
}
Expand All @@ -344,7 +339,7 @@
if (this.input)
{
this.input.removeEventListener('blur', this.stopEditingBinding);
this.input.removeEventListener('keyup', this.onKeyUpBinding);
this.input.removeEventListener('keydown', this.onKeyUpBinding);
this.input.removeEventListener('input', this.onInputBinding as EventListener);

this.input?.blur();
Expand Down Expand Up @@ -382,7 +377,7 @@
}

input.addEventListener('blur', this.stopEditingBinding);
input.addEventListener('keyup', this.onKeyUpBinding);
input.addEventListener('keydown', this.onKeyUpBinding);
input.addEventListener('input', this.onInputBinding as EventListener);

this.input = input;
Expand All @@ -392,6 +387,8 @@

protected handleActivation()
{
if (this.editing) return;

this.stopEditing();

if (this.activation)
Expand All @@ -416,12 +413,9 @@

if (this.value.length === 0) this.placeholder.visible = true;

if (isMobile.any)
{
this.input?.blur();
this.input?.remove();
this.input = null;
}
this.input?.blur();
this.input?.remove();
this.input = null;

this.align();

Expand Down Expand Up @@ -582,18 +576,7 @@
{
this.off('pointertap');

if (isMobile.any)
{
window.removeEventListener('touchstart', this.handleActivationBinding);
}
else if (!isMobile.any)
{
window.removeEventListener('click', this.handleActivationBinding);

window.removeEventListener('keyup', this.onKeyUpBinding);

window.removeEventListener('input', this.onInputBinding as EventListener);
}
window.removeEventListener(isMobile.any ? 'touchstart' : 'click', this.handleActivationBinding);

super.destroy(options);
}
Expand Down
Loading