Skip to main content

Tags & multi-select

Pick up to 3 interests from grouped options. They show as removable chips, with a clear-all button.

Loading…
import { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Select, useTheme } from 'patine-ui';

const INTERESTS: Record<string, string[]> = {
  Sports: ['Running', 'Cycling', 'Climbing', 'Surfing'],
  Arts: ['Photography', 'Painting', 'Music', 'Film'],
  Tech: ['AI', 'Mobile', 'Web', 'Hardware'],
};

const options = Object.entries(INTERESTS).flatMap(([group, items]) =>
  items.map((label) => ({ label, value: label.toLowerCase(), group }))
);

const MAX = 3;

export default function Tags() {
  const { colors } = useTheme();
  const [tags, setTags] = useState<string[]>(['climbing', 'ai']);
  return (
    <View style={styles.root}>
      <Select
        multiple
        label="Interests"
        placeholder="Add interests"
        sheetTitle={`Pick up to ${MAX}`}
        options={options}
        value={tags}
        onValueChange={setTags}
        maxSelected={MAX}
        clearable
      />
      <Text style={[styles.hint, { color: colors.textSecondary }]}>
        {tags.length}/{MAX} selected · tap a chip to remove it
      </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  root: { gap: 6, padding: 20 },
  hint: { fontSize: 12 },
});

Behaviour​

  • maxSelected disables the remaining options once the limit is hit; deselecting re-enables them.
  • Chip taps call onValueChange with the chip removed.
  • In multiple mode, × calls onValueChange([], []) for you.
  • onValueChange's second argument gives the full SelectOption objects, which is useful when you need labels:
onValueChange={(values, selected) => {
setTags(values);
analytics.track('Interests Changed', { labels: selected.map((o) => o.label) });
}}

Components used​

  • Select: multiple with chips, maxSelected, groups and clearable