Comments (7)
You are the one to thanks ;)
I updated the Github repo if it can help you to make the demo :)
from simple-keyboard.
The error makes senses because at OnInit
level, DOM is not created.
Still investigating how to process, using another lifecycle event (like AfterViewInit
)
EDIT:
using ngAfterViewInit
instead of ngOnInit
I have no more errors.
However CSS is not applied at all. We're almost done :)
EDIT2:
specifying the theme in options seems to solve the CSS problem! 👍
(github repo updated, as I'm pretty sure it could be useful to other people)
ngAfterViewInit() {
this.keyboard = new Keyboard(`.${ this.keyboardClassName }`,
{theme: 'simple-keyboard hg-theme-default hg-layout-default', });
}
from simple-keyboard.
Hey @ddahan,
You need to give a different class to each keyboard instance, otherwise the second instance will just override the first one.
For example:
<div class="simple-keyboard"></div>
<div class="keyboard2"></div>
let keyboard = new Keyboard({
// Options here
});
let keyboard2 = new Keyboard(".keyboard2", {
// Options here
});
Docs:
https://simple-keyboard.com/qa-use-cases/#give-different-class-keyboard
Demo:
https://codesandbox.io/s/github/hodgef/simple-keyboard-npm-demos/tree/uc-dispatch/
This should fix your issue, but if it doesn't let me know and we can look at this further.
Regards,
Francisco Hodge
from simple-keyboard.
Hi @hodgef and thanks for quick reply (and for your amazing job on this).
I understand that there is a conflict between 2 keyboards and I think I understood your code samples.
However, in Angular, the clean way to work when you want to use the same stuff several times is to create a unique component (this is what I did with SimpleKeyboardComponent
) and then, to include it with an app selector (here: <app-simple-keyboard></app-simple-keyboard>
, as many times as you want, in another component.
Looking at your code samples, it seems you want me to instanciate the component twice, which is impossible because the instanciation is made in the component itself.
So, the only two workarounds I can see right now would be :
- to NOT create a component at all for using keyboards in my app.
- to duplicate the
SimpleKeyboardComponent
into 2 different components.
In both cases, I think it's not ideal because it breaks the "Don't repeat Yourself" philosophy, if I want to use the same exact keyboard more than once.
Maybe this issue could be marked as "enhancement to respect Angular right way to do"
However, I'm not an expert at all in Angular so I let other people give their opinion about this.
Thanks again.
from simple-keyboard.
Awesome! Glad you got it figured out. I will update the Angular demos soon to use ngAfterViewInit
instead of onInit
. Thanks!
from simple-keyboard.
Hey @ddahan,
I understand what you mean. To accomplish this use case in react for example, I pass the class name to the component though a parameter (prop). Like so:
https://simple-keyboard.com/react/qa-use-cases/#give-different-class-keyboard
I wonder if using a similar approach would work for your use-case.
Something like this:
<app-simple-keyboard class="keyboard2"></app-simple-keyboard>
In any case, for multiple keyboards you do need multiple instances, as the event listeners, rows etc are bound to each keyboard's DOM element. Another approach would be to have a single keyboard serve all the inputs, like so:
https://simple-keyboard.com/qa-use-cases/#using-several-inputs
Hope this helps,
Francisco Hodge
from simple-keyboard.
You're right it's the way to go for sure.
In Angular, we have @input
to provide data to children components.
I tried to use @Input
to provide class name to the keyboard component., I think it's almost done, but something's wrong with the keyboard component instanciation, I got a DOM error:
Could you take a look to the updated code here please? https://github.com/ddahan/pockey
Thanks!!!
from simple-keyboard.
Related Issues (20)
- Add icons or images to buttons HOT 1
- your web is not opened HOT 1
- Prevent showing system keyboard on tablets HOT 3
- Support for mouse element HOT 2
- Japanese Flick Input (Mobile) HOT 3
- excludeFromLayout doesnt work HOT 2
- can i use in vue3? HOT 1
- Keyboard button not showing with tailwind HOT 2
- Not responsive on mobile HOT 1
- CSS partialy Apply HOT 1
- BackSpace Issue HOT 1
- need more layers (right alt) HOT 2
- Button Hold : Allow additional keys via options HOT 6
- `layoutCandidates` is not case sensitive HOT 1
- When simple-keyboard is used with accessibility voice over turned on, hitting q enters 1 in input HOT 1
- Simple-keyboard Not Rendering HOT 2
- When set layoutCandidatesPageSize = 15, There is an issue with the background color of the candidate box
- Not displaying keyboard outside app.component HOT 1
- Virtual Keyboard, keys are coming all white HOT 1
- Can this component be dragged by the mouse motor? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-keyboard.