ç®æ¬¡
ç®æ¬¡
ã¯ããã«
Ep.12ã§ã¯ãpart
å±æ§ã䜿çšããããšã®åé¡ã解決çãšããŠbehavior
å±æ§ã®ææ¡ããããŠãèŠçŽ ãCloneããŠã«ã¹ã¿ãã€ãºå¯èœã«ãã<selectedcontent>
ã®å¥æ©ã«ã€ããŠã話ãããŸããã
2024/12/9æç¹ã§ã®selectã®åããŒãã®å®çŸ©
Customizable Select Elementã®é¢é£ä»æ§
éžæããã<option>
ã®ã³ã³ãã³ãã<button>
ã«åæ ããããšã®æ£åœå
åœæã®<selectmenu>
ã®ä»æ§ã§ã¯ãã<slot name="selected-value">
ã«ãéžæããã<option>
ã®valueãåæ ããbehavior
å±æ§ã§å€éšããShadow DOMã®ã«ã¹ã¿ãã€ãºå¯èœã«ããããšããããšãŸã§å¯èœã§ãããïŒEp.12åç
§ïŒ
ãããããã¯ãã<option>
ã®valueã ãã§ãªããéžæããã<option>
å
èŠçŽ èªäœã®ã¯ããŒã³ãåæ ãã¹ãã ãããïŒåæ ãããšãããã©ã®ãããªææ³ã§è¡ãã¹ãã ãããïŒããšããè°è«ã«æ³¢åããŸãã
ãŸãããããå®è£
ããã¢ãããŒã·ã§ã³ãšãªããŠãŒã¹ã±ãŒã¹ãèãããããã¢ãã¿ãŒ + ååãããååã®ã¿ãããåœæ + åœåããªã©ã®äŸãæããããŸããã
ãã¢ãã¿ãŒ + ååãããåœæ + åœåãã®ããã«ããªãããªã³ã³ãã³ãã®å®å
šãªã¯ããŒã³ããšãªãå Žåãããã°ããååã®ã¿ãã®ããã«ããªãããªã³ã³ãã³ãã®äžéšã®ã¯ããŒã³ããšãªãå ŽåãèããããŸãã
ãã®ãŠãŒã¹ã±ãŒã¹èª¿æ»ã«ãããå®å
šãªã¯ããŒã³ãåæ ããããšã®ã¿ãªããããã®äžéšã®ã¿ã<select>
ã«è¡šç€ºã§ããããã«ããå¿
èŠããããšããåæãåããŸããã
åœæ + åœå ã¢ãã¿ãŒ + åå ååã®ã¿ïŒoptionã«ã¢ãã¿ãŒã¯ããããbuttonã«ã¯åæ ãããªãïŒ
éžæããã<option>
ã®ã³ã³ãã³ãã<button>
ã«åæ ããæ¹æ³ã®æ€èš
ãã®äžã§ãã©ãå®çŸãããã«ã€ããŠè°è«ããã以äžã®4ã€ã®æ¹æ³ãææ¡ãããŸããã
- Clone innerHTML of the option and insert that into the selected value part and leverage CSS to hide what you don't want rendered
- Provide an implicit slotting functionality
- Provide an attribute that enables referencing what content you want cloned
- Keep as it's currently defined which is to take the inner text of the option and insert that into the selected value part
<option>
ã®innerHTMLãã¯ããŒã³ããŠ<button>
ãžå®éã«æ¿å ¥ãã衚瀺ããããªãéšåã¯CSSã§é ã- éžæãããèŠçŽ ãæé»çã«
<button>
éšåãžã¹ãããããããšã§å®çŸãã- å±æ§ã«ãã£ãŠãã¯ããŒã³ãããã³ã³ãã³ããåç §ãã
<option>
å ã®ããã¹ãã<button>
ã«æ¿å ¥ãã(çŸåšã®ä»æ§ã®ãŸãŸ) https://github.com/openui/open-ui/issues/571#issuecomment-1298712385
ãŸãã2ã®ãéžæãããèŠçŽ ãæé»çã«<button>
éšåãžã¹ãããããããšã§å®çŸãããæ¹æ³ãå®çŸããã«ã¯ãããããããŠã³ãéããŠããç¶æ
ã®ãšããã¹ãããå
ã®éžæãããèŠçŽ ãããããããŠã³ã®äžã«ååšãã€ã€ãbuttonéšåãžã¹ãããããããªããã°ãªããŸããããããããã¹ããããã€ã€ãã¹ãããå
ã«ã衚瀺ããããå®çŸããæ©èœã¯ãçŸç¶ã®<slot>
ã§ã¯ãµããŒããããŠããŸããã
ð ã¯ããŒã³ãšã¹ããã:
ãããŸã§ã§äœåºŠãã¯ããŒã³ãšããè¡šçŸãšã¹ããããšããè¡šçŸãåºããã®ã§ãããã§äžåºŠæŽçããŠãããŸãã
- ã¯ããŒã³: DOMã®ä»æ§ã®äžéšã
Node.cloneNode()
ã䜿ã£ãŠãDOMããŒãèªäœãä»ã®å Žæã«è€è£œããããšãâè€è£œâãªã®ã§ãã¯ããŒã³å ã«ãå®æ ãæ®ããclonable
ãªShadow DOMå ã®èŠçŽ ãè€è£œããããšãã§ããã - ã¹ããã: DOMã®äžã§ããShadow DOMã®ä»æ§ã®äžéšãShadow Rootå
ã®
<slot>
ã眮ããç®æã«ãå€éšããèŠçŽ ãæ¿å ¥ããããã®ä»çµã¿ãslotå ã®èŠçŽ ã¯slotå ããåç §ãããslotå ã«å®æ ã¯ãªãã
ããã«é¢ããŠã¯ãContent Mirroringãå®è£
ãããããšã§å¯èœã«ãªããŸãããå®è£
ã®ç®åŠãç«ã£ãŠããªãïŒselectmenu
ãå®è£
ããããšãããããŒãã«ãé«ãå¯èœæ§ãããïŒã®ã§ãæ¡çšã¯èŠéããããšããããšããæ·±ãè°è«ãããŸããã§ããã
ãŸãã4ã®ã<option>
ã®innerTextã<button>
ã«æ¿å
¥ãããæ¹æ³ã¯ãããããã®è°è«ã§ãinnerHTMLãã¯ããŒã³ããææ³ãé©åããªãã»é£ãããšå€æãããå Žåã®ãæã劥åœãªéžæè¢ãšããç«ã¡äœçœ®ã«ãªããŸããã
ããã§ãå®éã«ã¯ããŒã³ããèŠçŽ ãæ¿å
¥ããããšã§ã衚瀺ããããã®ãšããããªããã®ãåºãåããããããéçºã®ããããã®èŠ³ç¹ãããæãåªããŠããã1ã®ã<option>
ã®innerHTMLãã¯ããŒã³ããŠ<button>
ãžå®éã«æ¿å
¥ãã衚瀺ããããªãéšåã¯CSSã§é ããæ¹æ³ã«ã€ããŠè©±ãåãããŠãããŸãã
innerHTMLãã¯ããŒã³ããããšã®åé¡
ãããã1ããµããŒãããäžã§ã®æžå¿µãäžãããŸãã
ãŸãã<option>
å
ã«IDãå«ãŸããŠããå Žåããã®IDãè€è£œãããããšã§ãããŒãžå
ã§IDã®éè€ãçºçããŸããããã«ãããJSãIDã§<option>
ã®ã³ã³ãã³ããã¯ãšãªããŠããå ŽåãinnerHTMLãã¯ããŒã³ããããšã§IDãéè€ããã¯ãšãªãå£ããå¯èœæ§ãææãããŸããã
ãŸãã<option>
èªäœãã³ããŒããã«ã<option>
ã®åèŠçŽ ã³ã³ãã³ããã¯ããŒã³ãããšããå®è£
ãããå Žåãã¹ã¿ã€ã«ãå£ããå¯èœæ§ããããŸãããäŸãã°ã以äžã®ãããªCSSãæžããŠã<option>
å
ã®ã³ã³ãã³ãïŒ.redOption
ïŒã«ã¹ã¿ã€ã«ãåœãŠãŠããå Žåã<option>
ã®ã³ã³ãã³ãã®ã¿ãã¯ããŒã³ããå®è£
ã§ã¯ãã¯ããŒã³ãããå
ã§ã¹ã¿ã€ã«ãåœãããŸããã
ãã®ããã<option>
èªäœãã¯ããŒã³ããå®è£
ã«ããã®ããšãããšã<button>
å
ã«<option>
ãååšããããšã«ãªããããŸãã«ãäžèªç¶ã§ãã
ãããŠã<option>
å
ã«Shadow Rootãããå Žåã®åãæ±ãã«ã€ããŠãèæ
®ãããã¹ããšããææããããŸãããåçŽãªinnerHTMLã§ã¯ãShadow Rootå
ã®ã³ã³ãã³ããååŸã§ããªããããã¯ããŒã³ãããŸããã
çŸç¶ã¯ã以äžã®ãããªJavaScriptãçšæããããšã§ãå®çŸãããããšã¯éæãããã®ã§ãããããæšæºåãããšããããŒãžéçºè
èªèº«ãå¿
èŠã«å¿ããŠã¹ã¯ãªãããçšããŠå®è£
ããããšãå¯èœã§ããéçºè
èªèº«ã§ãªããã€ã³å¯èœãªããšãããã§æšæºåãããšã<selectmenu>
èªäœã®Shipãé
ããŠããŸããšããã®ããJarharã®äž»åŒµã§ããã
ãããã®æšæºåã®é£ãããèžãŸãã<selectmenu>
ã§ã¯ãéžæããã<option>
ã®innerHTMLã®ã¯ããŒã³ãæšæºåãã¹ãã§ã¯ãªããšããçµè«ã«è³ããŸããã
åœæã®æç¹ã§ã¯ã代ããã«ãéçºè
ãå¿
èŠã«å¿ããŠãã¹ã¯ãªãããçšããŠãã®æ©èœãå®è£
ããããšãæšå¥šãããããšã«ãªããŸãã
RESOLVED: Don't implement behavior to copy innerHTML from the selected option into the selected value for V1 of selectmenu https://github.com/openui/open-ui/issues/571#issuecomment-1472206358
å°æ¥çã«ã¯ãå®è£ ãããå¯èœæ§ã®ããContent MirroringãçšããŠããªããã€ã³ã®åœ¢ã§ãã®æ©èœãæäŸããå¯èœæ§ãããããšã«ã觊ããããŠããã®è°è«èªäœã¯äžæŠãã®çµè«ã§ãŸãšãŸããŸããã
ã€ãŸãããã®æç¹ã§ã¯ãéžæãããèŠçŽ ãã¯ããŒã³ããŠã«ã¹ã¿ãã€ãºå¯èœã«ããããšã«é¢ããŠã¯è°è«ããããã®ã®ãäœãæ°ãã«ä»æ§çå®ããããšãããããšã¯ãªãã<selectmenu>
ã¯åŒãç¶ããslot
å±æ§ãšbehavior
å±æ§ã䜿çšããŠã«ã¹ã¿ãã€ãºããæ¹éã®ãŸãŸã§ããã
ãããªäžæèµ·ããããslot
å±æ§ãšbehavior
å±æ§ãžã®ç念ããããšãåã«åãããŸãã
ããã§ã¯ããŸãææ¥â
See you tomorrow!