Categories
React Suite

Developing Vue Apps with the Quasar Library — Input and Tag Pickers

Spread the love

Quasar is a popular Vue UI library for developing good looking Vue apps.

In this article, we’ll take a look at how to create Vue apps with the Quasar UI library.

Controlled Input Picker

We can add a controlled input picker with the value and onChange props.

For instance, we can write:

import React, { useState } from "react";
import { InputPicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";
const data = [
  {
    label: "Apple",
    value: "apple",
    role: "fruit"
  },
  {
    label: "Orange",
    value: "orange",
    role: "fruit"
  }
];
export default function App() {
  const [value, setValue] = useState();

  const handleChange = (val) => {
    setValue(val);
  };

  return (
    <div className="App">
      <InputPicker data={data} value={value} onChange={handleChange} />
    </div>
  );
}

value has the selected value.

handleChange has the val parameter to let us get the value from the input picker.

Then we can use that to set the value with setValue .

Tag Picker

We can add a dropdown to let us select tags with the TagPicker component.

For instance, we can write:

import React from "react";
import { TagPicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";

const data = [
  {
    label: "Apple",
    value: "apple"
  },
  {
    label: "Orange",
    value: "orange"
  }
];

export default function App() {
  return (
    <div className="App">
      <TagPicker data={data} style={{ width: 300 }} />
    </div>
  );
}

to add the tag picker.

The data prop lets us set the data we can select.

To change the size of the tag picker, we add the size prop:

import React from "react";
import { TagPicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";

const data = [
  {
    label: "Apple",
    value: "apple"
  },
  {
    label: "Orange",
    value: "orange"
  }
];

export default function App() {
  return (
    <div className="App">
      <TagPicker size="lg" data={data} />
    </div>
  );
}

lg makes it large.

We can also set it to xs to make it extra small, sm to make it small, and md to make it medium-sized.

The block prop lets us make the tag picker displayed as a block-level element.

For instance, we can write:

import React from "react";
import { TagPicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";

const data = [
  {
    label: "Apple",
    value: "apple"
  },
  {
    label: "Orange",
    value: "orange"
  }
];

export default function App() {
  return (
    <div className="App">
      <TagPicker block data={data} />
    </div>
  );
}

We can group the options with the groupBy prop:

import React from "react";
import { TagPicker } from "rsuite";
import "rsuite/dist/styles/rsuite-default.css";

const data = [
  {
    label: "Apple",
    value: "apple",
    role: "Fruit"
  },
  {
    label: "Orange",
    value: "orange",
    role: "Fruit"
  },
  {
    label: "Lettuce",
    value: "lettuce",
    role: "Vegetable"
  }
];

export default function App() {
  return (
    <div className="App">
      <TagPicker block data={data} groupBy="role" />
    </div>
  );
}

Conclusion

We can add controlled input pickers and tag pickers into our React app with React Suite.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *