@@ -413,6 +413,8 @@ store = await storage("my-data-store", storage_class=MyStorage)
413
413
414
414
### ` pyscript.web `
415
415
416
+ TODO: Use ` display(element) ` not ` element.display() ` .
417
+
416
418
The classes and references in this namespace provide a Pythonic way to interact
417
419
with the DOM. An explanation for how to idiomatically use this API can be found
418
420
[ in the user guide] ( ../user-guide/dom/#pyscriptweb )
@@ -424,14 +426,19 @@ This object has two attributes and a single method:
424
426
* ` head ` - a reference to a Python object representing the [ document's head] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head ) .
425
427
* ` body ` - a reference to a Python object representing the [ document's body] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body ) .
426
428
* ` find ` - a method that takes a single [ selector] ( https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors )
427
- argument and returns a collection of matching elements.
429
+ argument and returns a collection of Python objects representing the matching
430
+ elements.
431
+
432
+ These are provided as a convenience so you have several simple and obvious
433
+ options for accessing the content of the page (DOM).
428
434
429
- You have several options for accessing the
435
+ All the Python objects returned by these attributes and method are instances of
436
+ classes defined in the ` pyscript.web.elements ` namespace.
430
437
431
438
#### ` pyscript.web.elements.* `
432
439
433
440
There are many classes in this namespace. Each is a one-to-one mapping of any
434
- HTML element name for a Python class representing the HTML element of that
441
+ HTML element name to a Python class representing the HTML element of that
435
442
name. Each Python class ensures only valid properties and attributes can be
436
443
assigned, according to web standards.
437
444
@@ -472,6 +479,9 @@ Usage of these classes is
472
479
(`_`) because they are also keywords in Python, and the `grid` is a custom
473
480
class for a `div` with a `grid` style `display` property.
474
481
482
+ All these classes ultimately derive from the
483
+ `pyscript.web.elements.Element` base class.
484
+
475
485
In addition to properties defined by the HTML standard for each type of HTML
476
486
element (e.g. ` title ` , ` src ` or ` href ` ), all elements have the following
477
487
properties and methods (in alphabetical order):
@@ -482,15 +492,34 @@ properties and methods (in alphabetical order):
482
492
* ` classes ` - a set of CSS classes associated with the element.
483
493
* ` clone(clone_id=None) ` - Make a clone of the element (and the underlying DOM
484
494
object), and assign it the optional ` clone_id ` .
485
- * ` content ` - get or set the
486
- [ innerHTML] ( https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML )
487
- of the element.
488
495
* ` find(selector) ` - use a CSS selector to find matching child elements.
489
496
* ` parent ` - the element's parent element (that contains it).
490
497
* ` show_me ` - scroll the element into view.
491
498
* ` style ` - a dictionary of CSS style properties associated with the element.
492
499
* ` update(classes=None, style=None, **kwargs) ` - update the element with the
493
500
specified classes (set), style (dict) and DOM properties (kwargs).
501
+ * ` _dom_element ` - a reference to the proxy object that represents the
502
+ underlying native HTML element.
503
+
504
+ !!! info
505
+
506
+ All elements, by virtue of inheriting from the base `Element` class, may
507
+ have the following properties:
508
+
509
+ ```
510
+ accesskey, autofocus, autocapitalize,
511
+ className, contenteditable,
512
+ draggable,
513
+ enterkeyhint,
514
+ hidden,
515
+ innerHTML, id,
516
+ lang,
517
+ nonce,
518
+ part, popover,
519
+ slot, spellcheck,
520
+ tabindex, text, title, translate,
521
+ virtualkeyboardpolicy
522
+ ```
494
523
495
524
The ` classes ` set-like object has the following convenience functions:
496
525
@@ -501,8 +530,26 @@ The `classes` set-like object has the following convenience functions:
501
530
* ` replace(old_class, new_class) ` - replace the ` old_class ` with ` new_class ` .
502
531
* ` toggle(class_name) ` - add a class if it is absent, or remove a class if it
503
532
is present.
504
- * ` _dom_element ` - a reference to the proxy object that represents the
505
- underlying HTML element.
533
+
534
+ Elements that require options (such as the ` datalist ` , ` optgroup ` and ` select `
535
+ elements), can have options passed in when they are created:
536
+
537
+ ``` python
538
+ my_select = select_(option(" apple" , value = 1 ), option(" pear" ))
539
+ ```
540
+
541
+ Notice how options can be a tuple of two values (the name and associated value)
542
+ or just the single name (whose associated value will default to the given
543
+ name).
544
+
545
+ It's possible to access and manipulate the ` options ` of the resulting elements:
546
+
547
+ ``` python
548
+ selected_option = my_select.options.selected
549
+ my_select.options.remove(0 ) # Remove the first option (in position 0).
550
+ my_select.clear()
551
+ my_select.options.add(html = " Orange" )
552
+ ```
506
553
507
554
Finally, the collection of elements returned by ` find ` and ` children ` is
508
555
iterable, indexable and sliceable:
@@ -512,11 +559,12 @@ for child in my_element.children[10:]:
512
559
print (child.html)
513
560
```
514
561
515
- Furthermore, three attributes related to all elements contained in the
562
+ Furthermore, four attributes related to all elements contained in the
516
563
collection can be read (as a list) or set (applied to all contained elements):
517
564
565
+ * ` classes ` - the list of classes associated with the elements.
566
+ * ` innerHTML ` - the innerHTML of each element.
518
567
* ` style ` - a dictionary like object for interacting with CSS style rules.
519
- * ` html ` - the ` innerHTML ` of each element.
520
568
* ` value ` - the ` value ` attribute associated with each element.
521
569
522
570
### ` pyscript.when `
0 commit comments