Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="birth-date">
  <div class="birth-date__label">Дата рождения</div>
  <div class="birth-date__select-wrap">
    <select data-custom-select-class="select" class="select-day">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
      <option value="9">9</option>
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>
      <option value="15">15</option>
      <option value="16">16</option>
      <option value="17">17</option>
      <option value="18">18</option>
      <option value="19">19</option>
      <option value="20">20</option>
      <option value="21">21</option>
      <option value="22">22</option>
      <option value="23">23</option>
      <option value="24">24</option>
      <option value="25">25</option>
      <option value="26">26</option>
      <option value="27">27</option>
      <option value="28">28</option>
      <option value="29">29</option>
      <option value="30">30</option>
    </select>
    <select data-custom-select-class="select" class="select-month">
      <option value="Январь">Январь</option>
      <option value="Февраль">Февраль</option>
      <option value="Март">Март</option>
      <option value="Апрель">Апрель</option>
      <option value="Май">Май</option>
      <option value="Июнь">Июнь</option>
      <option value="Июль">Июль</option>
      <option value="Август">Август</option>
      <option value="Сентябрь">Сентябрь</option>
      <option value="Октябрь">Октябрь</option>
      <option value="Ноябрь">Ноябрь</option>
      <option value="Декабрь">Декабрь</option>
    </select>
    <select data-custom-select-class="select" class="select-year">
      <option value="1997">1997</option>
      <option value="1998">1998</option>
      <option value="1999">1999</option>
      <option value="2000">2000</option>
      <option value="2001">2001</option>
      <option value="2002">2002</option>
      <option value="2003">2003</option>
      <option value="2004">2004</option>
      <option value="2005">2005</option>
      <option value="2006">2006</option>
      <option value="2007">2007</option>
      <option value="2008">2008</option>
    </select>
  </div>
</div>
              
            
!

CSS

              
                .birth-date__label {
	font-family: $f-cn;
	font-size: 10px;
	line-height: 20px;
	margin-bottom: 6px;
	color: rgba($c-t, 0.5);
}

.birth-date__select-wrap {
	display: flex;
}

.select select {
	display: none;
}

.select {
	position: relative;
	display: inline-flex;
}

.select:not(:last-child) {
	margin-right: 5px;
}

.select__toggle {
	height: 34px;
	background-color: transparent;
	border: 1px solid #E8E8F2;
	border-radius: 10px;
	padding-left: 8px;
	padding-right: 35px;
}

.select--active {
	z-index: 1;
}

.select--active ~ .select {
	z-index: 0;
}

.select__options {
	max-height: 200px;
	overflow: auto;
	position: absolute;
	top: 100%;
	display: flex;
	flex-direction: column;
	visibility: hidden;
	background: white;
}

.select--active .select__options {
	visibility: visible;
}

.select__option--active {
	font-weight: bold;
}
              
            
!

JS

              
                const findElements = (object) => {
	const instance = object;
	const { node, select } = instance;
	instance.toggle = node.children[0];
	instance.holder = node.children[1];
	instance.isActive = false;
	instance.options = select.options;
	instance.active = select.selectedIndex >= 0 ? select.selectedIndex : 0;
	return instance;
};

const isOption = (target, { className }) => target.classList.contains(`${className}__option`);

const shouldDropdown = (target, { className }) => target.classList.contains(`${className}__option`);

const createBaseHTML = (value, className) => (`
	<div class="${className}">
		<button class="${className}__toggle" type="button">${value}</button>
		<div class="${className}__options"></div>
	</div>
`);

const insertBase = (select, className) => {
	const selectedIndex = select.selectedIndex >= 0 ? select.selectedIndex : 0;
	const value = select.options[selectedIndex].textContent;
	const html = createBaseHTML(value, className);
	select.insertAdjacentHTML('afterend', html);
};

const renderOption = (html, option, index, active, className) => {
		const activeClassName = index === active ? `${className}__option--active` : '';
  return `
    ${html}
				<button class="${className}__option ${activeClassName}" type="button" data-index="${index}">${option.textContent}</button>
  `;
};

const renderOptions = (options, active, className) => {
	return [...options].reduce((acc, option, index) => renderOption(acc, option, index, active, className), '');
};

const pickOption = (object) => {
	const instance = object;
	const { select, active, customOptions, className } = instance;
	select.selectedIndex = active;
	instance.optionActive.classList.remove(`${className}__option--active`);
	instance.optionActive = customOptions[active];
	instance.optionActive.classList.add(`${className}__option--active`);
	instance.toggle.textContent = instance.optionActive.textContent;
};

const onOptionsClick = (event, object) => {
	event.preventDefault();
	const instance = object;
	const { select, hideDropdown } = instance;
	const { target } = event;
	if (isOption(target, instance)) {
			instance.active = target.dataset.index;
			pickOption(instance);
	}
	if (shouldDropdown(target, instance)) {
		hideDropdown();
	}
};

const initOptionsEvents = (instance) => {
	instance.holder.addEventListener('click', event => onOptionsClick(event, instance));
};

const render = (object) => {
	const instance = object;
	const { holder, options, className, active } = instance;
	const html = renderOptions(options, active, className);
	holder.insertAdjacentHTML('afterbegin', html);
	instance.customOptions = [...holder.children];
	instance.optionActive = instance.customOptions[active];
	initOptionsEvents(instance);
};

const hideSelect = ({ node, select }) => node.appendChild(select);

const wrapSelect = (object) => {
	const instance = object;
	const { select, className } = instance;
	return new Promise((resolve) => {
		requestIdleCallback(() => {
			insertBase(select, className);
			instance.node = select.nextElementSibling;
			hideSelect(instance);
			resolve(instance);
		});
	});
};

const unsubscribeDocument = ({ hideDropdown }) => document.removeEventListener('click', hideDropdown); 
const subscribeDocument = ({ hideDropdown }) => document.addEventListener('click', hideDropdown);

const hideOptions = (object) => {
	const instance = object;
	const { node, className } = instance;
	instance.isActive = false;
	node.classList.remove(`${className}--active`);
	unsubscribeDocument(instance);
};

const showOptions = (object) => {
	const instance = object;
	const { node, className } = instance;
	instance.isActive = true;
	node.classList.add(`${className}--active`);
	subscribeDocument(instance);
};

const toggleOptions = (instance) => {
	if (instance.isActive) {
		hideOptions(instance);
	} else {
		showOptions(instance);
	}
};

const onNodeClick = event => event.stopPropagation();

const initEvents = (object) => {
	const instance = object;
	const { node, toggle } = instance;
	const showDropdown = () => { showOptions(instance); };
	const hideDropdown = () => { hideOptions(instance); };
	const toggleDropdown = () => { toggleOptions(instance); };
	instance.showDropdown = showDropdown;
	instance.hideDropdown = hideDropdown;
	instance.toggleDropdown = toggleDropdown;
	toggle.addEventListener('click', toggleDropdown);
	node.addEventListener('click', onNodeClick);
	return instance;
};

const constructor = (select) => {
	const instance = {
		select,
		className: select.dataset.customSelectClass,
	};
	
	const init = () => {
		wrapSelect(instance)
			.then(findElements)
			.then(initEvents)
			.then(render);
	};

	init();
};

const selects = document.querySelectorAll('[data-custom-select-class]');
selects.forEach(constructor);
              
            
!
999px

Console