The width of PrimeVue InputNumber is too wide for its parent container

I currently have a collection of items in the shopping cart that are displayed using Bootstrap rows and columns. Each item includes a PrimeVue InputNumber component for adjusting the quantity of a specific product within the cart.

If you'd like to explore the issue further, please check out this StackBlitz project by following this link.

This is how the InputNumber element is implemented:

<InputNumber v-model="item.qty"
             inputId="horizontal-buttons"
             showButtons
             buttonLayout="horizontal"
             :step="1"
             style="max-width: 100%; box-sizing: border-box;">
<template #incrementbuttonicon>
  <span class="material-symbols-sharp">
    add
  </span>
</template>
<template #decrementbuttonicon>
  <span class="material-symbols-sharp">
    remove
  </span>
</template>
</InputNumber>

Below is the component containing the aforementioned list:

<script setup>
import InputNumber from 'primevue/inputnumber'
import { useCartStore } from '../stores/cartStore.js'
import { storeToRefs } from 'pinia'

const cartStore = useCartStore()
const { cart } = storeToRefs(cartStore)
const { deleteFromCart } = cartStore
</script>

<template>
  <div class="row mw-2000 mx-auto px-lg-5 px-0 my-0">
    <section class="col-9">
      <div class="container-fluid">
        <div class="row border-top border-bottom cart-item"
             v-for="item in cart">
          <img class="col-2" :src="item.product.images[0]" alt="Product">
          <div class="col-6 d-inline-block overflow-ellipsis">
            {{ item.product.title }}
          </div>
          <div class="col-1 d-inline-block overflow-ellipsis">
            ${{ parseFloat(item.product.price).toFixed(2) }}
          </div>
          <div class="col-2">
            <InputNumber v-model="item.qty"
                         inputId="horizontal-buttons"
                         showButtons
                         buttonLayout="horizontal"
                         :step="1" style="max-width: 100%; box-sizing: border-box;">
              <template #incrementbuttonicon>
                <span class="material-symbols-sharp">
                  add
                </span>
              </template>
              <template #decrementbuttonicon>
                <span class="material-symbols-sharp">
                  remove
                </span>
              </template>
            </InputNumber>
          </div>
          <div class="col-1 d-flex justify-content-end">
            <button type="button"
                    class="btn btn-danger delete-product-btn d-inline-flex
                    justify-content-center align-items-center"
                    @click="deleteFromCart(item.product.id)">
              <span class="material-symbols-sharp">
                close
              </span>
            </button>
          </div>
        </div>
      </div>
    </section>
    <section class="col-3"></section>
  </div>
</template>

I've attempted applying

style="max-width: 100%; box-sizing: border-box;"
to the InputNumber component, but unfortunately, it hasn't yielded the desired result. Additionally, I've experimented with replacing max-width: 100% with width: 100%, without success. Currently, the input appears as shown:

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

Despite my efforts to diagnose the issue by inspecting the component, I haven't been able to identify any specific reason for this behavior. There doesn't appear to be any fixed-width settings applied to the InputNumber component. For a visual reference, please see the screenshots provided:
https://i.sstatic.net/8jyaGJTK.png
https://i.sstatic.net/6iLVX4BM.png

Just to clarify, my objective is to have the InputNumber element adjust to the width of its parent container.

Thank you for your assistance in advance!

Answer №1

Resolved the issue by implementing 1, 2:

.p-inputnumber input {
  width: 100%;
}

However, the underlying DOM mechanics are still unclear to me.

My assumption is that the user agent (browser) silently enforces the width, as stated in the HTML standard, ensuring that a minimum of 20 characters remain visible. This theory is supported by the input shrinking when the size attribute is set smaller than the default value of 20.

I thoroughly examined all CSS affecting span.p-inputnumber, its input child, the inner buttons, and the input's internal shadow DOM, but nothing explains the width exceeding the parent element.

Furthermore, the issue does not appear to stem from conflicting CSS rules between primevue and bootstrap (although combining them is not recommended, it is unlikely the root cause of the unintended CSS behavior).


1 - To apply this fix selectively on certain inputs, utilize a dedicated class.

2 - Setting the input's CSS overflow to auto, hidden, overlay, or scroll appears to yield the same result as the suggested fix (tested in Chrome only).

3 - If in your position, consider raising an issue on primevue's repository to report this behavior, as it is likely something they would want to address. Most developers anticipate the input element to adhere to the parent's width by default, without necessitating additional CSS adjustments.

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

Pass data from Symfony using an array of objects to a Vue.js component within a Twig template

I am currently working with symfony5 and I want to incorporate vue.js into one of my twig template views. My goal is to pass 3 different Objects to vue.js, each containing multiple Arrays which typically store several Objects. After installing vue.js, here ...

Restrictions of Vue Data Objects

I'm currently pondering the optimal amount of data to store in a Vue data object. Imagine I have over 4,000 objects structured like this: personWithAppointment = { id: 1, appointment_id: 1, first_name: 'Jim', last_name: 'Jim&ap ...

Preventing text from wrapping in a TypeScript-generated form: Tips and tricks

I’m currently working on a ReactJS project and my objective is simple: I want all three <FormItem> components to be displayed in a single line without wrapping. However, I am facing the following output: https://i.stack.imgur.com/mxiIE.png Within ...

JavaScript can intelligently extract and categorize an array of objects based on their properties

In essence, I aim to develop a versatile function "organize" that can transform the following data structure: [ { name: 'band1', type: 'concert', subtype: 'rock' }, { name: 'band2', type: 'concert' ...

What steps can I take to stop a select box within a flex container from shrinking?

Currently working on some code that involves a flex container. Struggling to prevent fields from shrinking too much on smaller screen sizes. var crsdesc; //var for new window function popup(mylink) { if (!window.focus) return true; var href; if (t ...

Efficiently managing classes with css modules and extractCSS in Nuxt 2

When using Nuxt 2 with CSS modules, I encountered an issue where multiple components resulted in multiple CSS files having the same class. Hello.vue <template> <div :class="$style.title">Hello, World</div> <div :class=&q ...

Setting up an Express route for updating data

I am in the process of developing a MEVN stack CRUD application (Vue, Node, Express, MongoDB). I am currently working on setting up an Express route for handling updates in my app... postRoutes.post('/update/:id', async(req, res)=> { cons ...

Adding a <span> element within an <h1> tag in WordPress

I am attempting to create this layout in Wordpress using the code <h1>This is my <span>title</span></h1>, but I am unsure how to incorporate a <span> tag within the <?php the_title(); ?> function. After consulting the c ...

Issue with Navbar collapse button not displaying items on Bootstrap 4.5.0 in combination with Next.js version 9.4.4

I'm currently working on a nextjs demo project where I'm incorporating bootstrap for styling purposes. The initial setup was straightforward as I installed bootstrap using npm and included it in my app.js. import 'bootstrap/dist/css/bootstra ...

JQueryUI dialog is falling short in terms of maximum width

I am experiencing an issue with a jqueryui dialog that I have defined with a maxWidth setting. $("#myDialog").dialog({ autoOpen: false, width: 'auto', maxWidth: 1000, height: 'auto', position: [2 ...

What causes the device pixel ratio to vary across different web pages on the same device and operating system?

I am curious about why device pixel ratio varies between different websites and operating systems. For instance, when using the same device, this site displays a different pixel ratio on Windows compared to Ubuntu. On Windows, the pixel ratio is 1.34 whi ...

Animating SVG elements using CSS

After learning how to use the <animate> attribute, I successfully created a captivating animation featuring an elastic line. However, I am now determined to transform this into CSS for better control: my goal is to activate the animation only upon ho ...

Basic Timer with Visual Background

Struggling to find the right CSS/script for a straightforward countdown timer, Here are the requirements: Countdown in days only, no need for hours, minutes, and seconds Ability to use a custom image as background I've scoured online searches but n ...

How can I add text to an HTML5 SVG similar to using the HTML5 <p> tag?

I am currently working on creating dynamic rectangular boxes and I am facing some difficulties with inserting text into the shapes. The SVG text requires setting x and y coordinates in separate text tags, and doesn't have built-in width and height pro ...

Choosing <label> elements, while disregarding those <label> elements that include <input>

I need assistance with CSS rules to target only <label> elements that do not contain an <input> field inside of them. Is there a specific rule I can use for this? <label for="type">Regular Label</label> <label for="type"> ...

Unable to display values in Fusion Charts zoomline chart using the showValues chart property

I'm struggling to figure out how to display the data plot values with showValues: '1' in a zoomline chart using Fusion Charts. You can see and test it on this fiddle: http://jsfiddle.net/60oeahc1/4/ Is there a way to make this feature work ...

Alternate Row Colors Using Odd/Even CSS Styling for Main Headings

In my expand/collapse table, I have set up alternating row colors (dark grey and light grey) that adjust automatically when expanding or collapsing. The challenge I'm facing is that for certain rows, I want to apply a specific background color using ...

Leveraging Vue2leaflet by including it through a <script src=... > import statement direct

Just diving into JavaScript for the first time, I'm looking to enhance the interactivity of my Python-created websites. Vue stands out to me as a compelling option, especially since I'd prefer to avoid using node/webpack, which are unfamiliar to ...

Issues are arising with Bootstrap's functionality within the Vite React app

I am new to working with react and vite. I am currently developing a vite react application that requires the use of bootstrap. I followed the instructions provided on the official Bootstrap website here. However, not all Bootstrap functionalities are work ...

Change WordPress links to parent page without altering the current URL

Having trouble with redirect rules for a single-page app within a sub-page of a Wordpress site. Despite following the provided instructions closely, issues persist. The subpages in question are custom post types for various business locations. Upon visitin ...