Skip to content
Tag Multi-Select preview
Rendered from the SwiftUI source on this page.

Tag Multi-Select

From syxUI — written for both platforms, not translated between them.

A self-contained tag multi-select — SwiftUI, styled from system tokens.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

ChipMultiSelectCard.swift
// Tag Multi-Select · syxUI · https://syxui.dev/components/form-chips
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Chip multi-select with add
struct ChipMultiSelectCard: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 10) {
            Text("SKILLS").font(.system(size: 11, weight: .semibold)).foregroundStyle(.secondary)
            FlowHStack(spacing: 8) {
                ForEach(["SwiftUI", "Design", "Motion"], id: \.self) { t in
                    HStack(spacing: 6) { Text(t).font(.system(size: 14, weight: .medium)); Image(systemName: "xmark").font(.system(size: 10, weight: .bold)).foregroundStyle(.secondary) }
                        .foregroundStyle(.primary).padding(.horizontal, 12).padding(.vertical, 8)
                        .background(Color.primary.opacity(0.06), in: Capsule())
                }
                HStack(spacing: 4) { Image(systemName: "plus").font(.system(size: 11, weight: .bold)); Text("Add").font(.system(size: 14, weight: .medium)) }
                    .foregroundStyle(.secondary).padding(.horizontal, 12).padding(.vertical, 8)
                    .overlay(Capsule().stroke(Color.primary.opacity(0.2), style: .init(lineWidth: 1, dash: [3, 3])))
            }
        }.formaCard()
    }
}


struct FlowHStack: Layout {
    var spacing: CGFloat = 8

    func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
        let maxWidth = proposal.width ?? .infinity
        var x: CGFloat = 0
        var y: CGFloat = 0
        var rowHeight: CGFloat = 0
        for s in subviews {
            let size = s.sizeThatFits(.unspecified)
            if x + size.width > maxWidth {
                x = 0
                y += rowHeight + spacing
                rowHeight = 0
            }
            x += size.width + spacing
            rowHeight = max(rowHeight, size.height)
        }
        return CGSize(width: maxWidth == .infinity ? x : maxWidth, height: y + rowHeight)
    }

    func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
        var x = bounds.minX
        var y = bounds.minY
        var rowHeight: CGFloat = 0
        for s in subviews {
            let size = s.sizeThatFits(.unspecified)
            if x + size.width > bounds.maxX {
                x = bounds.minX
                y += rowHeight + spacing
                rowHeight = 0
            }
            s.place(at: CGPoint(x: x, y: y), proposal: .unspecified)
            x += size.width + spacing
            rowHeight = max(rowHeight, size.height)
        }
    }
}
iOS 17 · 2 dependencies

Dependencies

SwiftUI
  • formaCard
  • FlowHStack

Requires iOS 17