Resize the p-accordion within a p-splitter using PrimeNG programmatically

Please find the code for my component below:

In this component, I have a p-splitter that is divided into 3 sections. Each section contains a p-accordion, which in turn includes a p-table.

<div class="card w-full">
        <p-splitter [panelSizes]="[30, 40, 30]" styleClass="mb-5">
            <ng-template pTemplate>
                <p-accordion [activeIndex]="0" styleClass="h-full">
                    <p-accordionTab header="Signed PDF Documents">
                        <div class="flex justify-content-between">
                            <div>
                                <h6>Proposal PDF Documents</h6>
                            </div>
                            <div><a>Add Attachment(s)</a></div>
                        </div>
                        <ng-template pTemplate>
                            <p-table [value]="documentList" styleClass="p-3 p-datatable-striped">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th pSortableColumn="name">Attachment Name
                                            <p-sortIcon field="name"></p-sortIcon>
                                        </th>                                            
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-doc>
                                    <tr>
                                        <td><a>{{ doc.name }}</a></td>
                                    </tr>
                                </ng-template>
                            </p-table> 
                        </ng-template>                              
                    </p-accordionTab>
                </p-accordion>   
            </ng-template>
...

I am facing two specific challenges:

  1. How can I ensure all accordion sections are of the same size, regardless of content? Currently, each accordion grows based on its content, but I want them to be uniform in size (the largest size among the three).
  2. Is there a way to prevent the splitter from being resized by the user? Currently, users can resize the splitter, but I would like to restrict this functionality. How can I achieve this?

I appreciate any assistance or guidance provided!

Warm regards,
Nitin Avula.

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

Answer №1

In most cases, component CSS is isolated to the component itself. However, we can utilize ::ng-deep to break this isolation and allow the CSS styles to affect elements outside of the component!

How do I ensure that all accordion elements have the same size, regardless of their dynamic content causing them to grow unevenly? How can I set a uniform size for all three accordions (based on the largest size)?

To achieve this, I include the following CSS code to ensure that the full height is applied to all accordion elements within the specified class custom-accordion, thereby containing the styling to the individual accordion:

HTML

...
<div class="card w-full custom-accordion" [ngClass]="{'no-resize': noResize}">
...

CSS

::ng-deep .custom-accordion .p-accordion-content {
    height: calc(100% - 54px) !important;
}

::ng-deep .custom-accordion .p-toggleable-content,
::ng-deep .custom-accordion .p-accordion-tab,
::ng-deep .custom-accordion p-accordiontab,
::ng-deep .custom-accordion .p-accordion {
    height:100% !important;
} 

Is there a way to prevent users from resizing the splitter element? How can I disable the resizing feature of the splitter?

If you wish to restrict the resizing functionality, you can hide the resize bar with the class p-splitter-gutter, applying the concept of scoping it to the accordion level using the class no-resize:

HTML

<button (click)="noResize = !noResize">toggle Resize</button>
{{noResize}}
<div class="card w-full custom-accordion" [ngClass]="{'no-resize': noResize}">
...

CSS

/* disable the resize */
::ng-deep .no-resize .p-splitter-gutter {
    display: none !important;
}

FULL CODE

TS

import { Component } from '@angular/core';
import { ImportsModule } from './imports';

@Component({
  selector: 'splitter-horizontal-demo',
  templateUrl: './splitter-horizontal-demo.html',
  
   // more TypeScript code here
  
})
export class SplitterHorizontalDemo {
  // TypeScript logic here
}

HTML

// HTML template code here

Stackblitz Demo

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

Using ngFor to display images with src attribute, merging information from two different properties within the loop

One issue I am facing involves an array with properties: export interface IGameTag{ name: string; relativePath: string; filename: string; } I understand that it is possible to include the filename in the relativePath like this: <div *ngFor=" ...

Enlarging the current division while reducing the size of the others when hovering

Currently, I am working on a school project that involves creating a slideshow on a webpage. However, I have reached a point where I am unsure of how to proceed. Here is the progress I have made so far: body { background-color: #252525; } #wrapper { ...

AngularJS remove a row from a table disrupts the formatting

Hello! I am attempting to delete rows from a table in Angular. I want the first two rows to have a red background and the rest to have a white background. If I try to delete the last row, it gets deleted but the color remains for the first row only (it sh ...

Encountering issues with NPM installation and a failed build process while working with

As someone new to working with Angular, I apologize if my question is basic. I've been given a new repository to work on, but I'm having trouble building it through the command line. When attempting to run npm install and npm start on my work p ...

Incorporating <span> elements into a comma-separated list using Jquery on every other item

When I receive a comma-separated list of items from a database and insert them into a table cell, I want to apply alternating styles to make it easier for users to distinguish between them. For example: foo, bar, mon, key, base, ball I'm looking to ...

Retrieving PHP information in an ionic 3 user interface

We are experiencing a problem with displaying data in Ionic 3, as the data is being sourced from PHP REST. Here is my Angular code for retrieving the data: this.auth.displayinformation(this.customer_info.cid).subscribe(takecusinfo => { if(takecusi ...

Exploring the hidden gems of npm package.json: the keys

There are some keys in the package.json file of Angular 2/4's source code that remain undocumented: { "name": "@angular/platform-browser/animations", "typings": "../animations.d.ts", "main": "../bundles/platform-browser-animations.umd.js", "m ...

Styling Angular2 Material Dialog: the perfect fit

The Angular2 material team recently unveiled the MDDialog module at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md I am interested in customizing the appearance of Angular2 material's dialog. Specifically, I want to adjust ...

Tips for resizing a larger image to display only a specific portion in CSS (and incorporating JS if needed)

I need to resize an image that measures 1024x1024 and is segmented into 4 quadrants: My goal is to reduce the size of this image so that quadrant 2 is 256x256 while masking out or hiding the remaining 3 quadrants, displaying only the desired section on th ...

Tips for containing a range slider within a div element in a flexbox container

I am currently using Javascript to generate a grid of images, and I want to include a range slider at the bottom of one of the images. Here is a simplified version of my code using flex-container: <style> .flex-container { display: flex; fle ...

mat-grid-list displaying in an unexpected manner

I am currently experimenting with integrating Angular Material into my project. Below is an example of the code I am using: <mat-grid-list cols="2" rowHeight="2:1"> <mat-grid-tile class="item-file-grid" *ngFor="let ind of [1,2,3,4]">& ...

Developing a JSP page by coding in html and css

Being a web designer, I find myself working on JSP pages to modify HTML and CSS for web application projects. However, I often feel confused by the JSP tags that I don't understand. Has anyone experienced this before? If so, how do you manage to edit ...

"Encountering an issue with the live preview feature in Br

Currently, I am working on a project offline and trying to make Brackets' live preview feature work smoothly. It has proven to be quite convenient for my tasks. While opening my project files using the "open file" option in Brackets, I encountered an ...

Using a Jquery selector with either the ID Regex or a repetitive class

There is a collection of similar elements with matching IDs Below are two methods for selecting them using Jquery: Select by ID + Regex (For example, How can I select an element by ID with jQuery using regex?) Add a redundant class to all the elemen ...

The div is not positioned on the left side

I'm struggling with aligning three divs next to each other in HTML and CSS. I've set them to float: left, but they are not obeying this style rule. .threethings { width: 20%; } .threethings div { text-align: center; position: relative; ...

Refreshing the page using location.reload triggers a reload of various elements

I am currently working on a website that supports multiple languages and utilizes a cookie named nav_lang to determine the user's preferred language for navigation. Whenever a user selects a new language, the cookie is updated accordingly and the page ...

Is there a way to eliminate the outline on a FormControl component in React-bootstrap when the input field is selected?

Currently, I'm working on creating a search bar with dropdown suggestions using React-bootstrap. My goal is to have the search bar span across the page from one side to another with margins on the left and right. To achieve this, I am enclosing the in ...

Adding Rows Dynamically to Material Data Table in Angular 7

Is there a way to dynamically add data from a service into my table? I am receiving data from AuthenticationService dialog and attempted using this.dataSource.push(this.transaction);, but it did not work as expected. This is the code snippet where I trie ...

Maintaining the position of an image during animation movements

I am experiencing an issue with a grid of images where, upon clicking one image, all the other images move down. However, the remaining image is pulled to the top left corner. I suspect this is happening because by removing the other images, the remaining ...

Unable to navigate through bootstrap dropdown items using keyboard shortcuts

I am currently working on a bootstrap dropdown menu that is filled with time zone details. Everything seems to be in order as the dropdown gets populated correctly. However, when I click on it and try to select an item by pressing a key on the keyboard (fo ...