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 : removed parent div from check box element #7164

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 4 additions & 12 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,25 +1104,18 @@ p5.prototype.createButton = function (label, value) {
p5.prototype.createCheckbox = function(...args) {
p5._validateParameters('createCheckbox', args);

// Create a container element
const elt = document.createElement('div');

// Create checkbox type input element
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';

// Create label element and wrap it around checkbox
const label = document.createElement('label');
//checkbox must be wrapped in label
const self = addElement(label, this);
// Append the checkbox to the label
label.appendChild(checkbox);

// Append label element inside the container
elt.appendChild(label);

//checkbox must be wrapped in p5.Element before label so that label appears after
const self = addElement(elt, this);

self.checked = function(...args) {
const cb = self.elt.firstElementChild.getElementsByTagName('input')[0];
const cb = self.elt.getElementsByTagName('input')[0];
if (cb) {
if (args.length === 0) {
return cb.checked;
Expand All @@ -1132,7 +1125,6 @@ p5.prototype.createCheckbox = function(...args) {
cb.checked = false;
}
}
return self;
};

this.value = function (val) {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,13 @@ suite('DOM', function() {

// helper functions
const getSpanElement = el =>
el.elt.firstElementChild.getElementsByTagName('span').length
? el.elt.firstElementChild.getElementsByTagName('span')[0]
el.elt.getElementsByTagName('span').length
? el.elt.getElementsByTagName('span')[0]
: null;

const getCheckboxElement = el =>
el.elt.firstElementChild.getElementsByTagName('input').length
? el.elt.firstElementChild.getElementsByTagName('input')[0]
el.elt.getElementsByTagName('input').length
? el.elt.getElementsByTagName('input')[0]
: null;

test('should be a function', function() {
Expand Down
Loading