Cycle Toggle

<cycle-toggle> Mature JS

Click to cycle through a variety of options

Features

Examples

Basic, no selected option:

<label for="mood">Mood:</label>
<cycle-toggle id="mood">
	<span>πŸ˜”</span>
	<span>πŸ˜•</span>
	<span>😐</span>
	<span>πŸ™‚</span>
	<span>πŸ˜€</span>
</cycle-toggle>

Pre-selected option:

<label for="mood2">Mood:</label>
<cycle-toggle id="mood2">
	<span>πŸ˜”</span>
	<span>πŸ˜•</span>
	<span>😐</span>
	<span aria-selected="true">πŸ™‚</span>
	<span>πŸ˜€</span>
</cycle-toggle>

With values (any child element works):

<label for="mood3">Mood:</label>
<cycle-toggle id="mood3">
	<data value="sad">πŸ˜”</data>
	<data value="neutral">😐</data>
	<data value="happy" aria-selected="true">πŸ™‚</data>
	<data value="elated">πŸ˜€</data>
</cycle-toggle>

With styles:

<cycle-toggle>
	<data value="" style="opacity: .4">πŸ‘πŸΌ</data>
	<data value="1">πŸ‘πŸΌ</data>
</cycle-toggle>

Readonly:

<cycle-toggle id="readonly_toggle" readonly>
	<span>πŸ˜”</span>
	<span>πŸ˜•</span>
	<span>😐</span>
	<span aria-selected="true">πŸ™‚</span>
	<span>πŸ˜€</span>
</cycle-toggle>
<button onclick="readonly_toggle.readonly = !readonly_toggle.readonly">Toggle readonly</button>

Set element.value:

<cycle-toggle id="toggle_rate">
	<data value="1">πŸ‘πŸΌ</data>
	<data value="-1">πŸ‘ŽπŸΌ</data>
</cycle-toggle>
<button onclick="toggle_rate.value = 1">Select πŸ‘πŸΌ</button>
<button onclick="toggle_rate.value = -1">Select πŸ‘ŽπŸΌ</button>

Dynamic aria-selected:

<cycle-toggle id="dynamic_selected">
	<span>πŸ˜”</span>
	<span>πŸ˜•</span>
	<span>😐</span>
	<span>πŸ™‚</span>
	<span>πŸ˜€</span>
</cycle-toggle>
<button onclick="dynamic_selected.children[3].setAttribute('aria-selected', 'true')">Select πŸ™‚</button>

Installation

Just include the component’s JS file and you’re good:

<script src="https://nudeui.com/elements/cycle-toggle/cycle-toggle.js" type="module"></script>

In case you want to link to local files: CSS is fetched automatically, and assumed to be in the same directory as the JS file.