Skip to content

Commit 8d53a24

Browse files
8HoLoNedimitchel
authored andcommitted
guide/components/attrs.md (vuejs-translations#173)
Co-authored-by: Michel EDIGHOFFER <[email protected]>
1 parent 1d04e3e commit 8d53a24

File tree

7 files changed

+56
-56
lines changed

7 files changed

+56
-56
lines changed

.vitepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const sidebar: ThemeConfig['sidebar'] = {
187187
]
188188
},
189189
{
190-
text: 'Components In-Depth',
190+
text: 'Composants en détails',
191191
items: [
192192
{
193193
text: 'Enregistrement',
@@ -196,7 +196,7 @@ export const sidebar: ThemeConfig['sidebar'] = {
196196
{ text: 'Props', link: '/guide/components/props' },
197197
{ text: 'Gestion des évènements', link: '/guide/components/events' },
198198
{
199-
text: 'Fallthrough Attributes',
199+
text: 'Attributs implicitement déclarés',
200200
link: '/guide/components/attrs'
201201
},
202202
{ text: 'Slots', link: '/guide/components/slots' },

src/api/component-instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ An object that contains the component's fallthrough attributes.
170170

171171
- **Details**
172172

173-
[Fallthrough Attributes](/guide/components/attrs.html) are attributes and event handlers passed by the parent component, but not declared as a prop or an emitted event by the child.
173+
[Attributs implicitement déclarés](/guide/components/attrs.html) are attributes and event handlers passed by the parent component, but not declared as a prop or an emitted event by the child.
174174

175175
By default, everything in `$attrs` will be automatically inherited on the component's root element if there is only a single root element. This behavior is disabled if the component has multiple root nodes, and can be explicitly disabled with the [`inheritAttrs`](./options-misc.html#inheritattrs) option.
176176

177177
- **See also:**
178178

179-
- [Fallthrough Attributes](/guide/components/attrs.html)
179+
- [Attributs implicitement déclarés](/guide/components/attrs.html)
180180

181181
## $watch()
182182

src/api/options-misc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Controls whether the default component attribute fallthrough behavior should be
104104

105105
</div>
106106

107-
- **See also:** [Fallthrough Attributes](/guide/components/attrs.html)
107+
- **See also:** [Attributs implicitement déclarés](/guide/components/attrs.html)
108108

109109
## components
110110

src/api/options-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Declare the custom events emitted by the component.
393393
394394
The validation function will receive the additional arguments passed to the component's `$emit` call. For example, if `this.$emit('foo', 1)` is called, the corresponding validator for `foo` will receive the argument `1`. The validator function should return a boolean to indicate whether the event arguments are valid.
395395
396-
Note that the `emits` option affects which event listeners are considered component event listeners, rather than native DOM event listeners. The listeners for declared events will be removed from the component's `$attrs` object, so they will not be passed through to the component's root element. See [Fallthrough Attributes](/guide/components/attrs.html) for more details.
396+
Note that the `emits` option affects which event listeners are considered component event listeners, rather than native DOM event listeners. The listeners for declared events will be removed from the component's `$attrs` object, so they will not be passed through to the component's root element. See [Attributs implicitement déclarés](/guide/components/attrs.html) for more details.
397397
398398
- **Example**
399399
@@ -429,7 +429,7 @@ Declare the custom events emitted by the component.
429429
}
430430
```
431431

432-
* **See also:** [Fallthrough Attributes](/guide/components/attrs.html)
432+
* **See also:** [Attributs implicitement déclarés](/guide/components/attrs.html)
433433

434434
## expose
435435

src/guide/components/attrs.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,163 +2,163 @@
22
outline: deep
33
---
44

5-
# Fallthrough Attributes
5+
# Attributs implicitement déclarés (Fallthrough Attributes) {#fallthrough-attributes}
66

7-
> This page assumes you've already read the [Components Basics](/guide/essentials/component-basics). Read that first if you are new to components.
7+
> Cette page suppose que vous avez déjà lu les [bases à propos des composants](/guide/essentials/component-basics). Lisez-les d'abord si vous débutez avec les composants.
88
9-
## Attribute Inheritance
9+
## Héritage d'attribut {#attribute-inheritance}
1010

11-
A "fallthrough attribute" is an attribute or `v-on` event listener that is passed to a component, but is not explicitly declared in the receiving component's [props](./props) or [emits](./events.html#declaring-emitted-events). Common examples of this include `class`, `style`, and `id` attributes.
11+
Un attribut implicitement déclaré (ou "fallthrough attribute") est un attribut ou un écouteur d'événement `v-on` qui est passé à un composant, mais qui n'est pas explicitement déclaré dans les [props](./props) ou les [émissions](./events.html#declaring-emitted-events) du composant récepteur. Des exemples courants de ceci incluent les attributs `class`, `style` et `id`.
1212

13-
When a component renders a single root element, fallthrough attributes will be automatically added to the root element's attributes. For example, given a `<MyButton>` component with the following template:
13+
Lorsqu'un composant affiche un seul élément racine, les attributs implicitement déclarés sont automatiquement ajoutés aux attributs de l'élément racine. Par exemple, le composant `<MyButton>` avec le template suivant :
1414

1515
```vue-html
16-
<!-- template of <MyButton> -->
16+
<!-- template de <MyButton> -->
1717
<button>click me</button>
1818
```
1919

20-
And a parent using this component with:
20+
Et un parent utilisant ce composant avec :
2121

2222
```vue-html
2323
<MyButton class="large" />
2424
```
2525

26-
The final rendered DOM would be:
26+
Le DOM rendu final serait :
2727

2828
```html
2929
<button class="large">click me</button>
3030
```
3131

32-
Here, `<MyButton>` did not declare `class` as an accepted prop. Therefore, `class` is treated as a fallthrough attribute and automatically added to `<MyButton>`'s root element.
32+
Ici, `<MyButton>` n'a pas déclaré `class` comme une prop acceptée. Par conséquent, `class` est traitée comme un attribut implicitement déclaré et automatiquement ajoutée à l'élément racine de `<MyButton>`.
3333

34-
### `class` and `style` Merging
34+
### Fusion de `class` and `style` {#class-and-style-merging}
3535

36-
If the child component's root element already has existing `class` or `style` attributes, it will be merged with the `class` and `style` values that are inherited from the parent. Suppose we change the template of `<MyButton>` in the previous example to:
36+
Si l'élément racine du composant enfant a déjà des attributs `class` ou `style` existants, il sera fusionné avec les valeurs `class` et `style` héritées du parent. Supposons que nous modifions le template de `<MyButton>` dans l'exemple précédent en :
3737

3838
```vue-html
39-
<!-- template of <MyButton> -->
39+
<!-- template de <MyButton> -->
4040
<button class="btn">click me</button>
4141
```
4242

43-
Then the final rendered DOM would now become:
43+
Ainsi, le DOM final rendu deviendrait :
4444

4545
```html
4646
<button class="btn large">click me</button>
4747
```
4848

49-
### `v-on` Listener Inheritance
49+
### Héritage de l'écouteur "v-on" {#v-on-listener-inheritance}
5050

51-
The same rule applies to `v-on` event listeners:
51+
La même règle s'applique aux écouteurs d'événements `v-on` :
5252

5353
```vue-html
5454
<MyButton @click="onClick" />
5555
```
5656

57-
The `click` listener will be added to the root element of `<MyButton>`, i.e. the native `<button>` element. When the native `<button>` is clicked, it will trigger the `onClick` method of the parent component. If the native `<button>` already has a `click` listener bound with `v-on`, then both listeners will trigger.
57+
L'écouteur de `click` sera ajouté à l'élément racine de `<MyButton>`, c'est-à-dire l'élément natif `<button>`. Lorsque le `<button>` natif est cliqué, il déclenchera la méthode `onClick` du composant parent. Si le `<button>` natif a déjà un écouteur de `click` lié à `v-on`, alors les deux écouteurs se déclencheront.
5858

59-
### Nested Component Inheritance
59+
### Héritage des composants imbriqués {#nested-component-inheritance}
6060

61-
If a component renders another component as its root node, for example, we refactored `<MyButton>` to render a `<BaseButton>` as its root:
61+
Si un composant rend un autre composant comme son nœud racine, par exemple, nous avons refactorisé `<MyButton>` pour rendre un `<BaseButton>` comme sa racine :
6262

6363
```vue-html
64-
<!-- template of <MyButton/> that simply renders another component -->
64+
<!-- template de <MyButton/> qui affiche uniquement un autre composant -->
6565
<BaseButton />
6666
```
6767

68-
Then the fallthrough attributes received by `<MyButton>` will be automatically forwarded to `<BaseButton>`.
68+
Alors, les attributs implicitement déclarés reçus par `<MyButton>` seront automatiquement transmis à `<BaseButton>`.
6969

70-
Note that:
70+
Notez que :
7171

72-
1. Forwarded attributes do not include any attributes that are declared as props, or `v-on` listeners of declared events by `<MyButton>` - in other words, the declared props and listeners have been "consumed" by `<MyButton>`.
72+
1. Les attributs transférés n'incluent aucun attribut déclaré en tant que props, ou écouteurs `v-on` d'événements déclarés par `<MyButton>` - en d'autres termes, les props et écouteurs déclarés ont été "consommés" par `<MyButton>`.
7373

74-
2. Forwarded attributes may be accepted as props by `<BaseButton>`, if declared by it.
74+
2. Les attributs transférés peuvent être acceptés comme props par `<BaseButton>`, s'ils sont déclarés par celui-ci.
7575

76-
## Disabling Attribute Inheritance
76+
## Désactivation de l'héritage d'attribut {#disabling-attribute-inheritance}
7777

78-
If you do **not** want a component to automatically inherit attributes, you can set `inheritAttrs: false` in the component's options.
78+
Si vous **ne souhaitez pas** qu'un composant hérite automatiquement des attributs, vous pouvez définir `inheritAttrs: false` dans les options du composant.
7979

8080
<div class="composition-api">
8181

82-
If using `<script setup>`, you will need to declare this option using a separate, normal `<script>` block:
82+
Si vous utilisez `<script setup>`, vous devrez déclarer cette option en utilisant un bloc `<script>` normal séparé :
8383

8484
```vue
8585
<script>
86-
// use normal <script> to declare options
86+
// utiliser le <script> normal pour déclarer les options
8787
export default {
8888
inheritAttrs: false
8989
}
9090
</script>
9191
9292
<script setup>
93-
// ...setup logic
93+
// ...mise en place de la logique
9494
</script>
9595
```
9696

9797
</div>
9898

99-
The common scenario for disabling attribute inheritance is when attributes need to be applied to other elements besides the root node. By setting the `inheritAttrs` option to `false`, you can take full control over where the fallthrough attributes should be applied.
99+
Le scénario courant de désactivation de l'héritage d'attribut est lorsque les attributs doivent être appliqués à des éléments autres que le nœud racine. En définissant l'option `inheritAttrs` sur `false`, vous pouvez prendre le contrôle total sur l'endroit où les attributs fallthrough doivent être appliqués.
100100

101-
These fallthrough attributes can be accessed directly in template expressions as `$attrs`:
101+
Ces attributs sont accessibles directement dans les expressions de template en tant que `$attrs` :
102102

103103
```vue-html
104104
<span>Fallthrough attributes: {{ $attrs }}</span>
105105
```
106106

107-
The `$attrs` object includes all attributes that are not declared by the component's `props` or `emits` options (e.g., `class`, `style`, `v-on` listeners, etc.).
107+
L'objet `$attrs` inclut tous les attributs qui ne sont pas déclarés par les `props` du composant ou options `emits` (par exemple, `class`, `style`, les écouteurs `v-on`, etc.).
108108

109-
Some notes:
109+
Quelques notes :
110110

111-
- Unlike props, fallthrough attributes preserve their original casing in JavaScript, so an attribute like `foo-bar` needs to be accessed as `$attrs['foo-bar']`.
111+
- Contrairement aux props, les attributs implicitement déclarés conservent leur casse d'origine en JavaScript, donc un attribut comme `foo-bar` doit être accédé en tant que `$attrs['foo-bar']`.
112112

113-
- A `v-on` event listener like `@click` will be exposed on the object as a function under `$attrs.onClick`.
113+
- Un écouteur d'événement `v-on` comme `@click` sera exposé sur l'objet en tant que fonction sous `$attrs.onClick`.
114114

115-
Using our `<MyButton>` component example from the [previous section](#attribute-inheritance) - sometimes we may need to wrap the actual `<button>` element with an extra `<div>` for styling purposes:
115+
En utilisant notre composant exemple `<MyButton>` de la [section précédente](#attribute-inheritance) - nous pouvons parfois avoir besoin d'envelopper l'élément `<button>` réel avec un `<div>` supplémentaire à des fins de style :
116116

117117
```vue-html
118118
<div class="btn-wrapper">
119119
<button class="btn">click me</button>
120120
</div>
121121
```
122122

123-
We want all fallthrough attributes like `class` and `v-on` listeners to be applied to the inner `<button>`, not the outer `<div>`. We can achieve this with `inheritAttrs: false` and `v-bind="$attrs"`:
123+
Nous voulons que tous les attributs implicitement déclarés tels que `class` et les écouteurs `v-on` soient appliqués au `<button>` sous-jacent, et non au `<div>`. Nous pouvons y parvenir avec `inheritAttrs: false` et `v-bind="$attrs"`:
124124

125125
```vue-html{2}
126126
<div class="btn-wrapper">
127127
<button class="btn" v-bind="$attrs">click me</button>
128128
</div>
129129
```
130130

131-
Remember that [`v-bind` without an argument](/guide/essentials/template-syntax.html#dynamically-binding-multiple-attributes) binds all the properties of an object as attributes of the target element.
131+
Rappelez-vous que [`v-bind` sans argument](/guide/essentials/template-syntax.html#dynamically-binding-multiple-attributes) lie toutes les propriétés d'un objet en tant qu'attributs de l'élément cible.
132132

133-
## Attribute Inheritance on Multiple Root Nodes
133+
## Héritage d'attributs sur plusieurs nœuds racine {#attribute-inheritance-on-multiple-root-nodes}
134134

135-
Unlike components with a single root node, components with multiple root nodes do not have an automatic attribute fallthrough behavior. If `$attrs` are not bound explicitly, a runtime warning will be issued.
135+
Contrairement aux composants avec un seul nœud racine, les composants avec plusieurs nœuds racine n'ont pas de comportement automatique concenant les attributs impliciitement déclarés. Si `$attrs` n'est pas lié explicitement, un avertissement lors de l'exécution sera émis.
136136

137137
```vue-html
138138
<CustomLayout id="custom-layout" @click="changeValue" />
139139
```
140140

141-
If `<CustomLayout>` has the following multi-root template, there will be a warning because Vue cannot be sure where to apply the fallthrough attributes:
141+
Si `<CustomLayout>` a le template multi-racine suivant, il y aura un avertissement car Vue ne sait pas où appliquer les attributs implicitement déclarés :
142142

143143
```vue-html
144144
<header>...</header>
145145
<main>...</main>
146146
<footer>...</footer>
147147
```
148148

149-
The warning will be suppressed if `$attrs` is explicitly bound:
149+
L'avertissement sera supprimé si `$attrs` est explicitement lié :
150150

151151
```vue-html{2}
152152
<header>...</header>
153153
<main v-bind="$attrs">...</main>
154154
<footer>...</footer>
155155
```
156156

157-
## Accessing Fallthrough Attributes in JavaScript
157+
## Accéder aux attributs implicitement déclarés en JavaScript {#accessing-fallthrough-attributes-in-javascript}
158158

159159
<div class="composition-api">
160160

161-
If needed, you can access a component's fallthrough attributes in `<script setup>` using the `useAttrs()` API:
161+
Si nécessaire, vous pouvez accéder aux attributs implicitement déclarés d'un composant dans `<script setup>` à l'aide de l'API `useAttrs()` :
162162

163163
```vue
164164
<script setup>
@@ -168,24 +168,24 @@ const attrs = useAttrs()
168168
</script>
169169
```
170170

171-
If not using `<script setup>`, `attrs` will be exposed as a property of the `setup()` context:
171+
Si vous n'utilisez pas `<script setup>`, `attrs` sera exposé en tant que propriété du contexte de `setup()` :
172172

173173
```js
174174
export default {
175175
setup(props, ctx) {
176-
// fallthrough attributes are exposed as ctx.attrs
176+
// les attributs implicitement déclarés sont exposés en tant que ctx.attrs
177177
console.log(ctx.attrs)
178178
}
179179
}
180180
```
181181

182-
Note that although the `attrs` object here always reflects the latest fallthrough attributes, it isn't reactive (for performance reasons). You cannot use watchers to observe its changes. If you need reactivity, use a prop. Alternatively, you can use `onUpdated()` to perform side effects with the latest `attrs` on each update.
182+
Notez que bien que l'objet `attrs` reflète toujours les derniers attributs implicitement déclarés, il n'est pas réactif (pour des raisons de performances). Vous ne pouvez pas utiliser d'observateurs pour observer ses changements. Si vous avez besoin de réactivité, utilisez une prop. De manière alternative, vous pouvez utiliser `onUpdated()` pour effectuer des tâches avec les derniers `attrs` à chaque mise à jour.
183183

184184
</div>
185185

186186
<div class="options-api">
187187

188-
If needed, you can access a component's fallthrough attributes via the `$attrs` instance property:
188+
Si nécessaire, vous pouvez accéder aux attributs implicitement déclarés d'un composant via la propriété d'instance `$attrs` :
189189

190190
```js
191191
export default {

src/guide/essentials/class-and-style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Will render:
243243
<span>This is a child component</span>
244244
```
245245

246-
You can learn more about component attribute inheritance in [Fallthrough Attributes](/guide/components/attrs.html) section.
246+
You can learn more about component attribute inheritance in [Attributs implicitement déclarés](/guide/components/attrs.html) section.
247247

248248
## Binding Inline Styles
249249

src/guide/reusability/custom-directives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ app.directive('demo', (el, binding) => {
210210

211211
## Usage on Components
212212

213-
When used on components, custom directives will always apply to a component's root node, similar to [Fallthrough Attributes](/guide/components/attrs.html).
213+
When used on components, custom directives will always apply to a component's root node, similar to [Attributs implicitement déclarés](/guide/components/attrs.html).
214214

215215
```vue-html
216216
<MyComponent v-demo="test" />

0 commit comments

Comments
 (0)