Materialize CSS Documentation

repository·main·Indexed 21 days ago

https://github.com/materializecss/materialize

A responsive front-end CSS framework based on Google's Material Design principles. Version 2.3.3 provides a collection of UI components including Chips with JavaScript plugin support, Navigation Bars, Checkboxes, Radio Buttons, and Dividers.

Tokens
12.8K
Snippets
55
Records
67
Agent score
76%

What's inside Materialize

  1. Create static Chips

    main

    You can create static chips using HTML. Chips are used to represent small blocks of information like contacts or tags.

    • Contact Chips: Include an <img> inside the .chip div.
    • Tag Chips: Include an element with the class close (e.g., a Material Icon) inside the .chip div.
    • Outlined Chips: Add the .outlined class to the .chip div.
    <!-- Contact Chip -->
    <div class="chip">
      <img src="images/yuna.jpg" alt="Contact Person"> Jane Doe
    </div>
    
    <!-- Tag Chip -->
    <div class="chip">
      Tag
      <i class="close material-icons">close</i>
    </div>
    
    <!-- Outlined Chip -->
    <div class="chip outlined">Information</div>
  2. Run tests locally

    main

    To run the test suite, you must first build the files. Once built, you can execute the tests using npm test.

    For detailed debugging and visual feedback, run the Jasmine browser runner and navigate to the provided local URL in your browser:

    1. Run npx jasmine-browser-runner.
    2. Open http://localhost:8888 in your browser.
    npm test
  3. Implement Checkboxes in Materialize CSS

    main

    Use checkboxes for binary choices (yes/no answers). To ensure the custom Materialize CSS checkbox is correctly bound to the input, you must use the for attribute on the <label> element. The value of the for attribute must match the id of the <input> element.

    <label>
      <input type="checkbox" />
      <span>Label Text</span>
    </label>
  4. Initialize the Chips Javascript Plugin

    main

    To use interactive chips (where users can type tags, use autocomplete, or delete chips), initialize the M.Chips plugin on one or more elements with the .chips class.

    Note on Data Format: In version 2.0.0+, the data option must follow the Chip data object structure (see Chip data object).

    document.addEventListener('DOMContentLoaded', function() {
      const elems = document.querySelectorAll('.chips');
      const instances = M.Chips.init(elems, {
        // specify options here
        autocompleteOptions: {
          data: [
            {id: 12, text: "Apple"},
            {id: 13, text: "Microsoft"},
            {id: 42, text: "Google", image: 'http://placehold.it/250x250'}
          ]
        },
        placeholder: 'Enter a tag',
        secondaryPlaceholder: '+Tag',
      });
    });
  5. Submit a Pull Request to Materialize

    main

    To contribute code, patches, or improvements, follow this workflow to ensure your work is eligible for merging:

    1. Fork and Clone: Fork the repository and clone your fork locally.
    2. Sync with Upstream: Always pull the latest changes from the upstream development branch (v2-dev) before starting work.
    3. Branching: Create a new topic branch for your specific changes.
    4. Commits: Use logical chunks and follow conventional commit format. You can use npm run commit to assist with formatting.
    5. Rebase/Merge: Periodically pull from upstream v2-dev into your topic branch to stay up to date.
    6. Push and PR: Push your topic branch to your fork and open a Pull Request against the current development branch (e.g., vX.X.X-dev). Reference any related issues in the description.

    Important Rules:

    • Do not edit materialize.css or materialize.js directly; these are auto-generated. Edit source files in sass/ and src/ instead.
    • Do not edit the gh-pages branch for documentation; edit source files in pug/page-contents/ on the v2-dev branch.
    # Clone your fork
    git clone https://github.com/<your-username>/materialize.git
    cd materialize
    
    # Assign the original repo to a remote called "upstream"
    git remote add upstream https://github.com/materializecss/materialize.git
    
    # Get latest changes from upstream development branch
    git checkout v2-dev
    git pull upstream v2-dev
    
    # Create a new topic branch
    git checkout -b <topic-branch-name>
    
    # After working, pull latest upstream changes into your branch
    git pull [--rebase] upstream v2-dev
    
    # Push your topic branch
    git push origin <topic-branch-name>
  6. Initialize Chips with different configurations

    main

    You can customize the behavior and appearance of Chips using specific CSS classes on the container element:

    • Normal: A standard chips container. Use <div class="chips"></div>.
    • Initial Tags: To pre-populate the container with existing tags, use the .chips-initial class.
    • Placeholders and Hints: To use custom placeholders or override hint texts, use the .chips-placeholder class.
    • Autocomplete: To enable autocomplete functionality within the chips input, use the .chips-autocomplete class.

    You can also provide a custom input element inside the chips container by nesting an <input> tag.

    <!-- Default with no input -->
    <div class="chips"></div>
    
    <!-- Set initial tags -->
    <div class="chips chips-initial"></div>
    
    <!-- Use placeholders and override hint texts -->
    <div class="chips chips-placeholder"></div>
    
    <!-- Use autocomplete with chips -->
    <div class="chips chips-autocomplete"></div>
    
    <!-- Customizable input -->
    <div class="chips">
      <input class="custom-class">
    </div>
  7. Use Chips to manage tags

    main

    Chips allow users to enter tag text and press enter to create a tag. Tags can be removed by clicking the close icon or using the delete button on the keyboard.

    Note on Breaking Changes: If you are migrating from version 1.X.X to 2.0.0, the data option format has changed. Ensure you update the data property in your initialization options to match the new 2.0.0 schema.

    <div class="chips"></div>