What are the steps to create fixed Angular Material Chips?

I'm currently attempting to achieve a similar look and functionality as demonstrated here: https://material.angularjs.org/1.1.9/demo/chips#static-chips where the chips are static and not selectable, clickable, or hoverable. However, I am utilizing Angular Material for this particular task.

Is it feasible to replicate this behavior using Angular Material? I am aware of the "Static Content" section in the Angular Material documentation that suggests:

<mat-chip-set role="list">
  <mat-chip role="listitem"> Sugar </mat-chip>
  <mat-chip role="listitem"> Spice </mat-chip>
  <mat-chip role="listitem"> Everything Nice </mat-chip>
</mat-chip-set>

Nevertheless, my attempt at implementing this resulted in undesirable outcomes. Specifically, I aim to:

  1. Eliminate the gray color when hovering over the mat-chip
  2. Remove the ripple effect upon clicking on the mat-chip (I discovered the possibility of achieving this using [disableRipple]="true"?)
  3. Get rid of the gray color upon clicking on the mat-chip

I prefer zero effects when interacting with the chip by either hovering or clicking. Is there a solution within Angular Material to accomplish this? The current state of my code is as follows:

<mat-chip-list class="privacy-tags">
  <mat-chip>Public</mat-chip>
  <mat-chip>Private</mat-chip>
  <mat-chip>Confidential</mat-chip>
</mat-chip-list>

UPDATE: Employing the following styling has led to these results:

.mat-chip {
    color: magenta !important;
    background-color: white !important;
    border: 1px magenta solid !important;
    pointer-events: none !important;
}

.mat-chip:hover {
    background-color: unset !important;
}

The left tag remains clickable while the right one does not:

https://i.sstatic.net/SSF3Q.png

In case of having only a single tag:

https://i.sstatic.net/IjCbW.png

Answer №1

To eliminate the ripple effect, you can set disableRipple to true. To customize the hover effect, you may modify the mat-chip element as shown below. Note that this was tested with Angular Material v15, which uses mat-chip-listbox instead of mat-chip-list:

HTML component template:

<mat-chip-listbox>
  <mat-chip [disableRipple]="true">Public</mat-chip>
  <mat-chip [disableRipple]="true">Private</mat-chip>
  <mat-chip [disableRipple]="true">Confidential</mat-chip>
</mat-chip-listbox>

SCSS component styles:

mat-chip {
  pointer-events: none; // consider using !important

  &:hover {
    background-color: unset; // consider using !important
  }
}

Alternatively, in .css file:

mat-chip {
  pointer-events: none;
}

mat-chip:hover {
  background-color: unset;
}

Answer №2

To enhance your CSS customization options, consider using mat-basic-chip-option or mat-basic-chip in place of mat-chip:

:host ::ng-deep .mat-mdc-basic-chip {
          border: 1px solid #cccccc;
          border-radius: 16px;
          width: 124px;
          height: 32px;
          text-align: center;
          cursor: pointer;
          &.mat-mdc-chip-selected {
            border: 2px solid purple;
            ;
            width: 114px;
            font-weight: bold;
            cursor: default;
          }
          &:hover {
            background-color: white !important;
          }
        }

Answer №3

Two choices available

  1. utilize <mat-chip>
  2. apply disabled using css
<mat-chip-set aria-label="Fish selection">
  <mat-chip>Select two fish</mat-chip>
  <mat-chip-option disabled class='chips'>Alert for fish</mat-chip-option>
</mat-chip-set>

View the code example here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding a file attachment and preview feature within a text area: a step-by-step guide

I have been working on a chat box that includes emojis and a file attachment button. While the emojis are functioning correctly, I am experiencing difficulty with the file attachment preview not showing in the text area. Are there any suggestions or plugin ...

jQuery Mobile elements remain resident in the memory

I'm currently working on a jQuery mobile app that includes a chart created with Highcharts, which can be exported using CanVG and canvas2ImagePlugin. However, I've noticed that the chart object remains in memory. As a result, if the page is opene ...

What methods can I use to troubleshoot queries being sent through mysql2?

According to the readme for mysql2: MySQL2 is mostly compatible with mysqljs This package includes an option described as: debug: This option prints protocol details to stdout. It can be set to true/false or an array of packet type names that should b ...

Is it possible to use Next Image to load multiple images within a loop effortlessly?

I have the following array of template types: const TEMPLATE_TYPES = [ { name: 'Blog Post', type: 'blog-post', img: '/img1.png' },... ]; In a later stage, I'm iterating over TEMPLATE_TYPE ...

Using .on as a substitute for live will not yield the desired results

I've been aware for some time now that the .on method is meant to replace .live, but I just can't seem to get it working. I've attempted: $(this).on('click', function(){ // Do something... }) $(this).on({ click: function ...

A div element featuring a border with transparent edges on the top right and bottom left corners

Does anyone know how to code the border for the upper right corner and lower left corner of the box (as shown in the image below)? I would really appreciate some help. Thank you in advance! This is the HTML <div class="carouselle"> <div clas ...

Creating an HTML element that can zoom, using dimensions specified in percentages but appearing as if they were specified in pixels

This question may seem simple, but I have been searching for an answer and haven't found one yet. Imagine we have an HTML element with dimensions specified in pixels: <div style="width:750px; height: 250px"></div> We can easily resize i ...

What is the location of the file storage while executing ng serve?

After running ng serve, where exactly are the generated files stored? I am facing an issue where the app works fine with ng serve but encounters problems during production build. I should also add that I am using the webpack version of angular-cli. ...

When using a CSS background image in ReactJS, a white space may appear at the bottom of the window

Currently, I am working on creating a background for a React website and implementing it in the div above component. My purpose is to have this background only appear on specific components and not throughout the entire website. However, I am encountering ...

What prevents me from displaying the image in the Bootstrap tooltip?

I am currently utilizing the Bootstrap framework v3.3.0 for my website. I'm trying to implement an image as a tool-tip when the user hovers their mouse pointer over an icon. Here is the HTML code I have: <div class="col-sm-5"> <div class= ...

showing the input field in United States Dollar (USD) currency format

I am currently facing an issue with a text field that is being retrieved from the database as a numeric value (e.g. 1234567). I would like to format this number into USD currency format, which should appear as $1,234,567. Could someone kindly assist me w ...

Breaking apart a string and mapping it to specific fields

My issue is relatively straightforward. Upon loading my page, a long string representing an address is generated. For example: 101, Dalmations Avenue, Miami, Florida, USA, 908343 With the help of jQuery, I can split the string using: var address = sel.o ...

Redefining the colors of an SVG when it is a CSS background image in code

I currently have an SVG icon encoded within my CSS file. I'm looking to change the color of this icon when a user hovers over it without creating a duplicate icon in a different color. Here's a snippet from my CSS file: background-image: url("d ...

Using media queries within specific CSS classes

I am attempting to create the following CSS code: .myClass { @media all (max-width: 1024px) { left: 33%; } @media all (min-width:1025px) { left: 25%; } } Unfortunately, it doesn't seem to be working as expected. Is t ...

Breaking down classes and cross-referencing them with a different DIV using JQuery

Trying to create a variable named relatedBoxes that will store checkboxes sharing similar classes as the box div. To do this, I am splitting up the classes and storing them in a variable called splitClass. Now, all that's left is to find out if any o ...

Which flow is best for single page applications: Implicit or Authorization Code in OpenID Connect?

OIDC offers multiple authentication flows, with Implicit and Auth Code flow being the two primary options available for SPAs. Recent discussions in the ietf mailing list suggest that Auth code flow is preferable to implicit flow due to security concerns su ...

Determine the output based on the data received from the ajax post request

I am seeking a way to validate my form based on the data returned. Currently, the validation only returns false if the entire post function is false. Is there a solution to differentiate how it is returned depending on which condition is met? This is my ...

Differences between visibility property manipulation in HTML and JS

One issue I am facing is that when I add a hidden property to a button in the HTML, it remains invisible. <button id="proceed_to_next_question" hidden> Next Question </button> However, if I remove the hidden property and include the following ...

Webkit feature: Rounded border image overlay

One issue arises when applying a rounded border to an image in webkit browsers as the border ends up hidden behind the image. CSS img { border: 10px solid #000; border-radius: 100%; } HTML <img src="http://25.media.tumblr.com/tumblr_mbje ...

Using an array to substitute a string in JavaScript

xyz1 xyz2 xyz3 xyz4 xyz5 xyz6 xyz7 xyz8 xyz9 Given the CSV above, transform the sentence below by removing the double quotes and replacing them with the corresponding values from the CSV: "" is going with "" to "" for something to know. ...