Fylgja Input Group

Ask AI

The Fylgja Input Group component allows you to group inputs and buttons together to create more intuitive form controls.

This component is ideal for building various UI elements such as search bars, button groups, or rating systems using radio buttons.

Installation

npm install @fylgja/input-group

Usage

Once installed, you can import the full package with:

@import "@fylgja/input-group";

Alternatively, if you only need specific parts, you can import them individually:

Import PathDescription
@fylgja/input-group/baseContains to core of the Input Group
@fylgja/input-group/mergeContains the --merge modifier class
@fylgja/input-group/stepsContains the --steps modifier class

Modifiers

--merge

The --merge modifier merges all borders between elements in an input group, making them appear as a unified component.

--steps

The --steps modifier adds stepping functionality, mainly used with radio buttons or checkbox groups to create a range-like input.

Examples

These examples demonstrate how you can use the Input Group component with various form controls and modifiers.

The flexibility of this component allows you to customize form elements easily.

Create a simple search bar by combining an input field with a button:

<form action="./search/">
	<label for="ui-search">Search</label>
	<div class="input-group">
		<input id="ui-search" name="ui-search"/>
		<button>Search</button>
	</div>
</form>

Button Group

Create a group of buttons with the --merge modifier for a seamless design:

<div class="input-group --merge">
	<button>Delete</button>
	<button>Update</button>
	<button>Publish</button>
</div>

You can also use checkboxes to create a toolbar. The btn class hides the input and makes the label the interactive element:

<div class="input-group --merge">
	<label class="btn">
		<input type="checkbox"/>
		Mute
	</label>
	<label class="btn">
		<input type="checkbox"/>
		Pause
	</label>
</div>

Start Rating

Use the --steps modifier to create a rating system with radio buttons, giving it the appearance of a step-by-step input:

Your Rating
<fieldset>
	<legend>Your Rating</legend>
	<div class="input-group --steps">
		<label>
			<svg ...><use href="#star" /></svg>
			<input type="radio" name="demo-star-rating"/>
		</label>
		...
	</div>
</fieldset>

FAQ

What's the difference between merge and the default input-group?

By default, input-group just groups elements together. The merge modifier additionally collapses the borders between them so the group reads as one unified control, as in the Button Group and Search box examples.

Can steps modifier be used with something other than radio buttons or checkboxes?

The documented use case is radio buttons or checkboxes to build a range-like or star-rating input, as shown in the "Start Rating" example. It isn't documented for other input types.

Do I need custom JavaScript to make the star rating example work?

No, the rating example relies purely on native radio button behavior and CSS (via the steps modifier and a shared name attribute). No JavaScript is required for the visual state shown.

Can I mix a text input and multiple buttons in the same input group?

Yes, input-group doesn't restrict which elements you combine. The Search box example pairs a single input with one button, and you can extend that pattern with more inputs or buttons as needed.