question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Components - default settings

See original GitHub issue

Is your feature request related to a problem? Please describe. Most of my apps made by Quasar are targeted to touch devices. If you use q-tooltip it has a default tooltip position below the object. It is problematic on touch devices as it appears under your finger and tooltip is not visible.

You can easily define new position <q-tooltip anchor="top middle" self="center middle">Mark as favorite</q-tooltip> but you have to do it for each component.

Describe the solution you’d like Would be nice to configure a default settings for some components not only q-tooltip. Other components for default settings could be q-btn or q-input.

I think it could work in the same way as it is now for e.g. q-notify setDefaults Settings defaults.

Describe alternatives you’ve considered I can always wrap Quasar component into my own and pass default properties.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yusufkandemircommented, Sep 23, 2022

Here is a slightly different variant of @pdanpdan’s approach, with some really basic TypeScript sprinkled on top:

import { QInput, QInputProps, QSelect, QSelectProps } from 'quasar';
import { boot } from 'quasar/wrappers';

const defaultsQInput: Partial<QInputProps> = {
  filled: true,
  dense: true,
  color: 'red',
  type: 'number',
  inputClass: 'text-right',
};

const defaultsQSelect: Partial<QSelectProps> = {
  filled: true,
  dense: true,
  inputClass: 'text-right',
};

export default boot(() => {
  Object.entries(defaultsQInput).forEach(([prop, value]) => {
    assignDefault(QInput.props, prop, value);
  });

  Object.entries(defaultsQSelect).forEach(([prop, value]) => {
    assignDefault(QSelect.props, prop, value);
  });
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function assignDefault(props: any, prop: string, value: any) {
  /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
  props[prop] =
    Array.isArray(props[prop]) === true || typeof props[prop] === 'function'
      ? { type: props[prop], default: value }
      : { ...props[prop], default: value };
  /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
}
1reaction
pdanpdancommented, Sep 23, 2022

I would go with something like this (to prevent having to fill everything in the prop):

import { QInput } from 'quasar'
import { boot } from 'quasar/wrappers'

const defaultsQInput = {
  filled: true,
  dense: true,
  color: 'red',
  type: 'number',
  inputClass: 'text-right'
}

export default boot(() => {
  Object.keys(defaultsQInput).forEach(prop => {
    QInput.props[ prop ] = Array.isArray(QInput.props[ prop ]) === true || typeof QInput.props[ prop ] === 'function'
      ? { type: QInput.props[ prop ], default: defaultsQInput[ prop ] }
      : { ...QInput.props[ prop ], default: defaultsQInput[ prop ] }
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Component Settings and Properties Reference | Microsoft Learn
Component settings are the configurable aspects of each component in a Windows installation. For example, you can configure the Windows Internet ...
Read more >
Setting Default Values for Selecting Components - PTC Support
The default values are set in the Creo Parametric Options dialog box, either as configuration options or as Component retrieval settings.
Read more >
Configuring components - IBM
For default components, you can edit only the name and description. Procedure. In the Solution Administration view, click Configuration Tools > Component ......
Read more >
To set the site-wide default component configuration
To set the site-wide default component configuration. (Website Administrator only). Insert the component. Depending on the component, you can insert it into ...
Read more >
How to Set Default Style to a React Component | Pluralsight
This is the general approach for setting default styles in React. The double pair of curly braces is reduced to a single one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found